<?php
$link=mysql_connect(‘localhost’,’root’,”);
if(!$link){
echo “connect failed”;
exit;
}
$sql=’use student’;
mysql_query($sql,$link);
//增加
$sql=”insert into student(sname,sage) values(‘pu’,’20’)”;
$rs=mysql_query($sql,$link);
if($rs){
echo ‘insert data success’.”<br />”;
}else{
echo ‘insert data failed’.”<br />”;
}
//修改
$sql=”update student set sname=’fu’ where sname=’pu'”;
$rs=mysql_query($sql,$link);
if($rs){
echo ‘update data success’.”<br />”;
}else{
echo ‘update data failed’.”<br />”;
}
//删除
$sql=”delete from student where sname=’li'”;
$rs=mysql_query($sql,$link);
if($rs){
echo ‘del data success’.”<br />”;
}else {
echo ‘del data failed’.”<br />”;
}
//查询
$sql=”select * from student”;
$rs=mysql_query($sql,$link);
//打印变量的相关信息
var_dump($rs);
//遍历从结果集中取行 mysql_fetch_array/assoc/row/object
while($row=mysql_fetch_assoc($rs)){
print_r($row);
echo ‘ ‘;
echo $row->sname;
echo “<br />”;
}
?>
请先 登录 !