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 ...
随机推荐
- c#中设置按钮Button为透明
方法一:代码实现 /// <summary> /// 设置透明按钮样式 /// </summary> private void SetBtnStyle(Button btn) ...
- POJ刷题记录 (。・`ω´・)(Progress:6/50)
1743:前后作差可以转化成不可重叠最长公共字串问题,运用后缀数组解决(参考罗穗骞神犇的论文) #include <cstdio> #include <cstring> #in ...
- 永久关闭防火墙和selinux
临时关闭selinux: setenforce 0 //设置SELinux 成为permissive模式 彻底禁用selinux: 使用root用户,vim /etc/sysconfig/sel ...
- PHP表单
二.PHP表单 1.PHP表单处理 welcome.html <html> <body> <form action="welcome.php" met ...
- php之图片处理类缩略图加水印
用到两个image系统函数 imagecopymerge — 拷贝并合并图像的一部分 imagecopyresampled — 重采样拷贝部分图像并调整大小 /* 如何知道图片的大小和类型 无法确认调 ...
- TortoiseSVN显示图标不正常
Windows Explorer Shell支持的Overlay Icon最多15个,除去系统使用,只有11个.如果其他程序占用了,那么乌龟SVN就无法显示了.注册表定位到:HKEY_LOCAL_MA ...
- MongoDB 复制集模式Replica Sets
1.概述 复制集是一个带有故障转移的主从集群.是从现有的主从模式演变而来,增加了自动故障转移和节点成员自动恢复. 复制集模式中没有固定的主结点,在启动后,多个服务节点间将自动选举 产生一个主结点.该主 ...
- 【转】HTML5 LocalStorage 本地存储
原文见:http://www.cnblogs.com/xiaowei0705/archive/2011/04/19/2021372.html 说到本地存储,这玩意真是历尽千辛万苦才走到HTML5这一步 ...
- python与编码方式
1.编码方式: ASCII编码:用来表示英文,它使用1个字节表示,其中第一位规定为0,其他7位存储数据,一共可以表示128个字符. 拓展ASCII编码:用于表示更多的欧洲文字,用8个位存储数据,一共可 ...
- test about cnblog
there is nothing here. This is only a test about cnblog!