今天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的更多相关文章

  1. The 11th tip of DB Query Analyzer

          The 11th tip of DB Query Analyzer                                            MA Gen feng       ...

  2. October 11th 2016 Week 42nd Tuesday

    A friend is one who knows you and loves you just the same. 朋友就是懂你并爱你的人. Leave nothing for tomorrow w ...

  3. September 11th 2016 Week 38th Sunday

    Nothing happens unless first a dream. 一切始于梦想. When everything seems to be going against you, remembe ...

  4. August 11th 2016, Week 33rd Thursday

    A particular fine spring came around. 转眼又是一番分外明媚的春光. Hey, it is hot outside, sometimes even unbearab ...

  5. July 11th, Week 29th Monday, 2016

    I want to win a trophy, it's the most important. 我希望获得冠军奖杯,这是最重要的事情. Win a trophy, stand on the very ...

  6. UVaLive 7512 November 11th (思维漏洞)

    题意:给定n*m个座椅,然后有b个是坏的,要做人,并且两个人不能相邻,问你最多坐多少人,最少坐多少人. 析:这个题其实并不难,只要当时一时没想清楚,结果就一直WA,就是最少的情况时,其实一个人可以占三 ...

  7. The 11th Zhejiang Provincial Collegiate Programming Contest->Problem G:G - Ternary Calculation

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3782 题意:把输入的三元运算用计算机运算出来. ;          ci ...

  8. The 11th Zhejiang Provincial Collegiate Programming Contest->Problem A:A - Pokemon Master

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3776 题意:比较两组数据的总和大小. #include <iostr ...

  9. ELK beats平台介绍(11th)

    beats是一个代理,将不同类型的数据发送到elasticsearch.beats可以直接将数据发送到elasticsearch,也可以通过logstash将数据发送elasticsearch. be ...

随机推荐

  1. (java)从零开始之-反射Reflect

    反射: 当一个字节码文件加载到内存的时候,jvm会对该字节码进行解剖,然后会创建一个对象的Class对象,把字节码文件的信息全部都存储到该Class对象中,我们只要获取到Class对象,我们就可以使用 ...

  2. ScheduleThreadPoolExecutor源码分析(二)

    DelayedWorkQueue: DelayedWorkQueue实现了BlockingQueue接口,因此其可以作为线程池的任务队列.BlockingQueue的主要属性有以下几个: privat ...

  3. C++前置++与后置++的区别与重载

    ++属于单目运算符,前置与后置的实现代码不一样,下面以整数自增为例: // 前置++,返回自增后的值,且返回的是一个左值 int& operator++(){ *this += 1; retu ...

  4. nim

    上帝创造了一个n*m棋盘,每一个格子都只有可能是黑色或者白色的. 亚当和夏娃在玩一个游戏,每次寻找边长为x的正方形,其中每个格子必须为黑色,然后将这些格子染白. 如果谁不能操作了,那么那个人就输了. ...

  5. jQuery实现公告文字左右滚动的代码。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. AppiumDriver 运行app启动基本参数

    记录一下 DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(Mobile ...

  7. css学习--inline-block详解及dispaly:inline inline-block block 三者区别精要概括

    *知识储备: 内联元素:是不可以控制宽和高.margin等:并且在同一行显示,不换行. 块级元素:是可以控制宽和高.margin等,并且会换行. 1.inline-block 详解 (1)一句话就是在 ...

  8. 使用模版引擎填充重复dom元素

    引入arttemplate,定义newajax发送跨域请求获得数据,将获得的数据用定义的格式渲染 <!DOCTYPE html><html lang="en"&g ...

  9. House Of Hello恶搞包为什么如此受热捧!

    凤凰时尚    在大多数人的心中,奢侈品都是昂贵的,摆在精美的橱窗中,动辄上万的价格,高贵而冷艳,也让很多人望而却步.然而,最近在很多时尚年轻一族中却流传着这样一句话“昂贵不等于奢侈,奢侈是一种生活态 ...

  10. sublime text3入门笔记以及屏蔽sublime自动升级检测更新

    两个月前学习python的时候,有人推荐这个程序员最好用的编辑器,我下载了之后,发现比notepad++要好用很多,目前来说,网上成熟的版本是sublime text2简体中文版,插件也是很兼容,我用 ...