php连接Mysql的增删改查操作
程序员文章站
2024-01-13 16:31:34
...
$conn=mysql_connect('localhost','root','');
if(!$conn){
echo "connect failed";
exit;
}
$sql='use student';
mysql_query($sql,$conn);
//增加
$sql="insert into student(sname,sage) values('pu','20')";
$rs=mysql_query($sql,$conn);
if($rs){
echo 'insert data success'."
";
}else{
echo 'insert data failed'."
";
}
//修改
$sql="update student set sname='fu' where sname='pu'";
$rs=mysql_query($sql,$conn);
if($rs){
echo 'update data success'."
";
}else{
echo 'update data failed'."
";
}
//删除
$sql="delete from student where sname='li'";
$rs=mysql_query($sql,$conn);
if($rs){
echo 'del data success'."
";
}else {
echo 'del data failed'."
";
}
//查询
$sql="select * from student";
$rs=mysql_query($sql,$conn);
//打印变量的相关信息
var_dump($rs);
//遍历从结果集中取行 mysql_fetch_array/assoc/row/object
while($row=mysql_fetch_object($rs)){
print_r($row);
echo ' ';
echo $row->sname;
echo "
";
}
?>
if(!$conn){
echo "connect failed";
exit;
}
$sql='use student';
mysql_query($sql,$conn);
//增加
$sql="insert into student(sname,sage) values('pu','20')";
$rs=mysql_query($sql,$conn);
if($rs){
echo 'insert data success'."
";
}else{
echo 'insert data failed'."
";
}
//修改
$sql="update student set sname='fu' where sname='pu'";
$rs=mysql_query($sql,$conn);
if($rs){
echo 'update data success'."
";
}else{
echo 'update data failed'."
";
}
//删除
$sql="delete from student where sname='li'";
$rs=mysql_query($sql,$conn);
if($rs){
echo 'del data success'."
";
}else {
echo 'del data failed'."
";
}
//查询
$sql="select * from student";
$rs=mysql_query($sql,$conn);
//打印变量的相关信息
var_dump($rs);
//遍历从结果集中取行 mysql_fetch_array/assoc/row/object
while($row=mysql_fetch_object($rs)){
print_r($row);
echo ' ';
echo $row->sname;
echo "
";
}
?>
以上就介绍了php连接Mysql的增删改查操作,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
推荐阅读
-
php连接Mysql的增删改查操作
-
node连接mysql生成接口,vue通过接口实现数据的增删改查(一)
-
PHP简单操作MongoDB的方法(安装及增删改查),mongodb增删
-
php连接不上mysql但mysql命令行操作正常的解决方法
-
求php+mysql实现快讯信息的增删改查代码
-
php中操作memcached缓存进行增删改查数据的实现代码,phpmemcached
-
.NET连接数据库以及基本的增删改查操作教程
-
PHP使用数据库永久连接方式操作MySQL的是与非
-
Java Maven:spring boot + Mybatis连接MySQL,通用mapper的增删改查,映射实现多表查询
-
php中操作memcached缓存进行增删改查数据的实现代码