今天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. 使用OC开发phonegp 组件

    使用OC开发phonegp 组件 1. 使用oc 对phonegp中的组件近些开发,首先具体的pgonegp跟nativecode之间的一些优劣就不说了,开发phonegp 对应的组件主要就是使用na ...

  2. cas sso单点登录系列8_抛弃Https让Cas以Http协议提供单点登录服务

    转:http://blog.csdn.net/ycyk_168/article/details/18668951 本文环境: 1.apache-tomcat-7.0.50-windows-x86 2. ...

  3. SGU 113.Nearly prime numbers

    水一个代码: #include <iostream> using namespace std; int n, a; bool ok; bool prime (int x) { ; i * ...

  4. IE下空链接失效原因及解决方法

    我们把a链接的display设置为block,但如果对该标签设置为position:absolute后,会发现在ie6.ie7下有时点击无效,ie8下有效(ie8标准),使用zoom:1方式也无法解决 ...

  5. WF学习笔记(一)

    -流程启动方式1: WorkflowInvoker.Invoke(new Workflow1()); -流程启动方式2: WorkflowApplication instance = new Work ...

  6. absolut绝对定位的非绝对定位用法

    一.absolute绝对定位的流行用法 一般而言,我们会用absolute绝对定位做什么呢?就是绝对定位,顾名思意,定死在某个位置上.例如,lightbox效果就是使用的绝对定位,例如新浪微博的弹出提 ...

  7. extjs下拉框添加复选框

    给ComboBox组件配置listConfig 下拉框代码: var gyslxcm = Ext.create('Ext.form.field.ComboBox',{ id : 'gyslxcm', ...

  8. ssh远程登录Ubuntu报错:Permission denied, please try again.

    ssh到server上的时候密码是对的但是报如下信息:# ssh 172.16.81.221root@172.16.81.221's password:Permission denied, pleas ...

  9. hdu3652B-number

    Problem Description A wqb-number, or B-number for short, is a non-negative integer whose decimal for ...

  10. Unity干中学——如何实现类似Windows Store 应用程序和Android Toast的通知?

    要实现通知中心功能,首先要创建一个游戏物体,在上面挂载GUITeture和GUIText脚本.注意GUITexture和GUIText脚本的顺序,GUITexture在前,GUIText在后,否则GU ...