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 ...
随机推荐
- 设置 textField.placeholder的颜色和大小
textField.placeholder = @"请输入手机号码"; [textField setValue:[UIColor blue] forKeyPath:@"_ ...
- jQuery实现页面元素智能定位
实现过程 Js侦听滚动事件,当页面滚动的距离(页面滚动的高度)超出了对象(要滚动的层)距离页面顶部的高度,即要滚动的层到达了浏览器窗口上边缘时,立即将对象定位属性position值改成fixed(固定 ...
- javascript事件详解1
事件流讲解来袭,嘎嘎嘎嘎嘎 ---------------------------------------------------------------- 1.事件流:描述的是在页面中接受事件的顺序 ...
- 基于ProGuard-Maven-Plugin的自定义代码混淆插件
介绍 大家可能都会碰到一些代码比较敏感的项目场景,这个时候代码被反编译看到就不好了,这个时候就需要代码混淆插件来对代码进行混淆了. 基于Maven的项目一般会去考虑使用proguard-maven-p ...
- 解决linux .so的链接时符号依赖问题
问题描述 target: a.out SO:libmyfile.so 依赖描述: a.out: libmyfile.so libmyfile.so: libssl.so.1.0.0 libssl.s ...
- 常见的iis日志代码!
2xx 成功 200 正常:请求已完成. 201 正常:紧接 POST 命令. 202 正常:已接受用于处理,但处理尚未完成. 203 正常:部分信息 — 返回的信息只是一部分. 204 ...
- Fedora 21 安装Infinality
原文地址: Fedora 21 用infinality美化你的字体 http://blog.csdn.net/element207/article/details/41746683 安装infinal ...
- .net程序员必须知道的知识
A while back, I posted a list of ASP.NET Interview Questions. Conventional wisdom was split, with ab ...
- odoo view field option, action flage 参数
options JSON object specifying configuration option for the field's widget (including default widget ...
- Tornado 的教材
Tornado 的教材 作者:杨昆链接:https://www.zhihu.com/question/19707966/answer/12731684来源:知乎著作权归作者所有,转载请联系作者获得授权 ...