PHP连接MYSQL数据库
<p>04级新生名单</p>
<table border="1" width="80%" cellpadding="0">
<tr>
<td width="10%" align="center">Id</td>
<td width="20%" align="center">Name</td>
<td width="10%" align="center">Age</td>
<td width="10%" align="center">Sex</td>
<td width="30%" align="center">Address</td>
<td width="20%" align="center">DoWith</td>
</tr>
<?php
//连接数据库
//打开一个连接,连接到本地mysql数据库
$conn=mysql_connect("localhost","root","dalyluo");//ip,user,pwd
//选择操作的资料库
mysql_select_db("test",$conn);// 资料库名称,连接
$sql="select * from student";
//用mysql_query函数从资料库中查询
mysql_query("set names gbk");//处理中文乱码问题,gbk可以是其它值
$result=mysql_query($sql,$conn);// search sql, connection
//循环读取记录
while($row=mysql_fetch_array($result)){
?>
<tr>
<td width="10%" align="center"><?php echo $row["stuid"] ?></td>
<td width="20%" align="center"><?php echo $row["stuname"] ?></td>
<td width="10%" align="center"><?php echo $row["stuage"] ?></td>
<td width="10%" align="center"><?=$row["stusex"]?></td>
<td width="30%" align="center"><?=$row["stuaddress"]?></td>
<td width="20%" align="center"><a href="#" mce_href="#" onClick="<?php doDel($row["stuid"]) ?>">删除</a></td>
</tr>
<?php
}
//关闭连接
mysql_close($conn);
function doDel($sid){
global $conn;
mysql_select_db("test",$conn);
$del_sql="delect from student where stuid="+$sid;
mysql_query($del_sql,$conn);
}
?>
</table>
相关文档:
MYSQL 8小时 断开链接问题
解决办法有两个:第一是设置autoReconnect属性设置为true;第二是设置DBCP 时将testquery等几个属性一并设置。
问题的原因是,MySQL的参数interactive_timeout,也就是交互超时时间默认为8小时。也就是如果一个链接在8小时后,还没有和服务器交互,这个连接就会被MySQL服务器断开。因为MySQL能 ......
搞了很久。。终于发现原来是权限问题。。
2行命令搞定
grant all privileges on rogue.* to admin@localhost identified by 'admin' with grant option
grant all privileges on rogue.* to admin@'%' identified by 'admin' with grant option
经典了。。。
魔力私服网页端搞定咯~~ ......
# MySQL-Front 5.1 (Build 4.2)
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */;
/*!40101 SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES */;
/*!40103 SET SQL_NOTES='ON' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS */ ......
上一篇我们讲到链接到 Edit.php?id= 来修改数据,后来我想了一下,其实也可以直接利用 Input.php 来修改数据,这样更容易管理,节省了不必要的空间
Input.php可以这样链接:Input.php?id=[Num]&action=[Num]
id即记录ID,默认为-1
action为动作,默认为0 , 为0时代表添加新的记录,为1时则修改记录
In ......
1. 安装mysql的时候选择字符集utf8
2. 安装结束后修改my.ini,有两个地方要修改,
[mysql] default-character-set=gbk
# The default character set that will be used when a new schema or table is
# created and no character set ......