11th day
今天MySQL数据库的基本知识就学完了,明天开始做小项目什么的,有点小激动啊...
<?php
// 定义$sql语句执行函数
function my_query($sql){
$result = mysql_query($sql);
if(!$result){
echo 'SQL语句执行失败.';
echo '<br>错误代号:',mysql_errno();
echo '<br>错误信息:',mysql_error();
}
return $result;
} // 定义数据库连接认证函数
function my_connect($arr){
$host = isset($arr['host']) ? $arr['host'] : 'localhost';
$port = isset($arr['port']) ? $arr['port'] : '3306';
$user = isset($arr['user']) ? $arr['user'] : 'root';
$pass = isset($arr['pass']) ? $arr['pass'] : '';
$link = @ mysql_connect("$host:$port",$user,$pass);
if(!$link){
echo '数据库连接失败.';
echo '<br>错误代号:',mysql_errno();
echo '<br>错误信息:',mysql_error();
die;
}
} // 定义字符编码函数
function my_charset($arr){
$charset = isset($arr['charset']) ? $arr['charset'] : 'utf8';
$sql = "set names $charset";
my_query($sql);
} // 选择使用的数据库函数
function my_dbname($arr){
$dbname = isset($arr['dbname']) ? $arr['dbname'] : '';
$sql = "use $dbname";
my_query($sql);
} //确定数据库的配置信息
$arr = array(
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'pass' => 'admin',
'charset' => 'utf8',
'dbname' => 'db1'
); // 连接数据库
my_connect($arr); // 设置字符编码
my_charset($arr); // 选择使用的数据库
my_dbname($arr);
?>
这个有点好用啊,另外我表示基本已经不会css和js了,忘得贼快...
<?php
header("content-type:text/html;charset=utf-8"); include "./mysql_DB.php"; $sql = 'select * from product';
$result = my_query($sql); ?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>产品信息</title>
<style>
*{
margin:0px;
padding:0px;
}
table{
margin:20px auto;
border-collapse:collapse;
width:600px;
}
.th{
padding:5px;
background-color:orange;
line-height:30px;
height:30px;
}
.td{
text-align:center;
line-height:30px;
height:30px;
}
</style>
</head>
<body>
<table border='1'>
<tr class='th'>
<th>产品ID</th>
<th>名称</th>
<th>类型</th>
<th>价格</th>
<th>品牌</th>
<th>产地</th>
</tr>
<?php while($row = mysql_fetch_assoc($result)): ?>
<tr class='td'>
<td><?php echo $row['pro_id'] ?></td>
<td><?php echo $row['pro_name'] ?></td>
<td><?php echo $row['protype_id'] ?></td>
<td><?php echo $row['price'] ?></td>
<td><?php echo $row['pinpai'] ?></td>
<td><?php echo $row['chandi'] ?></td>
</tr>
<?php endWhile; ?>
</table>
</body>
</html>
11th day的更多相关文章
- The 11th tip of DB Query Analyzer
The 11th tip of DB Query Analyzer MA Gen feng ...
- October 11th 2016 Week 42nd Tuesday
A friend is one who knows you and loves you just the same. 朋友就是懂你并爱你的人. Leave nothing for tomorrow w ...
- September 11th 2016 Week 38th Sunday
Nothing happens unless first a dream. 一切始于梦想. When everything seems to be going against you, remembe ...
- August 11th 2016, Week 33rd Thursday
A particular fine spring came around. 转眼又是一番分外明媚的春光. Hey, it is hot outside, sometimes even unbearab ...
- July 11th, Week 29th Monday, 2016
I want to win a trophy, it's the most important. 我希望获得冠军奖杯,这是最重要的事情. Win a trophy, stand on the very ...
- UVaLive 7512 November 11th (思维漏洞)
题意:给定n*m个座椅,然后有b个是坏的,要做人,并且两个人不能相邻,问你最多坐多少人,最少坐多少人. 析:这个题其实并不难,只要当时一时没想清楚,结果就一直WA,就是最少的情况时,其实一个人可以占三 ...
- The 11th Zhejiang Provincial Collegiate Programming Contest->Problem G:G - Ternary Calculation
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3782 题意:把输入的三元运算用计算机运算出来. ; ci ...
- The 11th Zhejiang Provincial Collegiate Programming Contest->Problem A:A - Pokemon Master
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3776 题意:比较两组数据的总和大小. #include <iostr ...
- ELK beats平台介绍(11th)
beats是一个代理,将不同类型的数据发送到elasticsearch.beats可以直接将数据发送到elasticsearch,也可以通过logstash将数据发送elasticsearch. be ...
随机推荐
- ZendStudio快捷键
Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行Ctrl+Alt+↓ 复制当前行到下一行(复制增加)Ctrl+Alt+↑ 复制当前行到上一行(复制增加)Alt+↓ 当前 ...
- 将日期和时间作为 struct tm型的值直接向二进制文件进行读写
#include <stdio.h> #include <time.h> char data_file[]="D:\\%\\datetime.dat"; v ...
- ecshop后台根据条件查询后不填充table 返回的json数据,content为空?
做ecshop后台开发的时,根据条件查询后,利用ajax返回的content json数据内容为空,没有填充table 效果 预期效果 问题: make_json_result($smarty -&g ...
- DEDECMS会员注册如何配置邮箱发送邮件功能
网站邮件功能是一个非常基础和有效的通信工具,配合dede会员注册邮件验证功能可以大量的拒绝垃圾注册用户.那么如何配置DEDECMS会员注册邮箱发送邮件功能? 1:配置dedecms网站发信EMAI ...
- Android Fragment基础及使用
同一个app内的界面切换 用Fragment比较合适,因为Activity比较重量级 Fragment 轻量级,切换灵活 --------------------------------------- ...
- CSS3的appearance属性--改变元素的外观
CSS3 appearance 属性 CSS 参考手册 实例 使 div 元素看上去像一个按钮: div { appearance:button; -moz-appearance:button; /* ...
- centos升级python到2.7
最近在阿里云租了一个云主机,打算部署自己的个人网站,但是centos系统的默认Python是2.6版本,打算升级到2.7.3! 查看python的版本 #python -V Python 2.6.6 ...
- gcc常用的编译选项
一.程序编译过程 程序编译的时候,要分四个阶段 : 1.预处理阶段,完成宏定义和include文件展开等工作: 2.根据编译参数进行不同程度的优化,编译成汇编代码: 3.用汇编器把汇编代码进一步生成目 ...
- 3ds max 2016 新功能
3ds max 2016 新功能_MCG节点编辑器 这是介绍视频下载: http://pan.baidu.com/s/1gds4wqJ
- 151111 sqlite3数据库学习
最近在学习数据库,想起去年做的项目里用到了sqlite3.那时候,没有任何的数据库经验,误打误撞,找到了sqlite3,然后参考网络上零碎的信息,把它嵌入到工程里,并且成功了.可惜,那时候没有好好保存 ...