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>
相关文档:
在网上看了很多关于windows2003+iis6+php+mysql 服务器配置的文章,大体上都是互相抄袭,不过一些公共的信息还是很正确的,但是针对一些特别的机器或者因为个人不同的配置总不能按照文章的内容操作成功,下面说一种较为简单的操作方法,步骤如下:
1.iis安装(略)
2.下载AppServ并安装
3.在c:\建php5文件夹,然后再php5 ......
如下php代码
<?php
$type='a';
$target='type';
$a=array(1,2,3);
a($target);
function a($type)
{
global $$type;
var_dump($$type);
}
?>
预计输出的是string(1)”a”
可是结果是
Notice: Undefined variable: a in D:\web\global.php on ......
上一篇我们讲到链接到 Edit.php?id= 来修改数据,后来我想了一下,其实也可以直接利用 Input.php 来修改数据,这样更容易管理,节省了不必要的空间
Input.php可以这样链接:Input.php?id=[Num]&action=[Num]
id即记录ID,默认为-1
action为动作,默认为0 , 为0时代表添加新的记录,为1时则修改记录
In ......
假如我们的mysql有一个计数器,而这个计数器需要我们重新统计,怎么办呢?
应用场景,比如说有一个商场,每卖一个产品都产生一个流水,然后我们需要知道每笔流水是该产品第几次出售的,这样说可能不明白,我拿一个详细的数据
举例吧。
recordID,productID,productType,sellDate,counter
1, 1, 1, '2010-1-15 15:20:10 ......
MySQL导出和导入SQL脚本
导出sql脚本:
mysqldump -u 用户名 -p 数据库名 > 存放位置
mysqljump -u root -p test > c:\a.sql
导入sql脚本:
要建环境变量或者在bin的目录下,mysql这个命令才能识别。
test是你要导进去的数据库名字,要提前建好~~
mysql -u 用户名 -p 数据库名 < 存放位置
mysqljump -u ro ......