1. 云栖社区>
  2. PHP教程>
  3. 正文

PHP增删改查代码

作者:用户 来源:互联网 时间:2017-11-30 17:17:06

php代码删改

PHP增删改查代码 - 摘要: 本文讲的是PHP增删改查代码, <?php //init.php $conn = mysqli_connect('127.0.0.1','root','','xz',3306); $sql = "SET NAMES UTF8"; mysqli_query($con

<?php	//init.php	$conn = mysqli_connect('127.0.0.1','root','','xz',3306);	$sql = "SET NAMES UTF8";	mysqli_query($conn,$sql);?>
<?php	//插入	@$uname = $_REQUEST['uname'];	if($uname === null || $uname === ""){		die("uname required");	}	@$upwd = $_REQUEST['upwd'];	if($upwd === null || $upwd === ""){		die("upwd required");	}	@$email = $_REQUEST['email'];	if($email === null || $email === ""){		die("email required");	}	@$phone = $_REQUEST['phone'];	if($phone === null || $phone === ""){		die("phone required");	}	require("init.php");	$sql = "INSERT INTO xz_user(uname,upwd,email,phone) VALUES('$uname','$upwd','$email','$phone')";	$result = mysqli_query($conn,$sql);	if($result === false){		echo "操作失败";	}else{		$uid = mysqli_insert_id($conn);		echo $uid;		echo "操作成功";	}?>
<?php	//删除	@$uid = $_REQUEST['uid'];	if($uid == null || $uid === ""){		die("uid required");	}	require('init.php');	$sql = "DELETE FROM xz_user WHERE uid='$uid'";	$result = mysqli_query($conn,$sql);	if($result === false){		echo "操作错误";	}else{		$count = mysqli_affected_rows($conn);		if($count > 0){			echo "操作成功";		}else{			echo "记录不存在";		}	}?>
<?php	//更新	@$uid = $_REQUEST['uid'];	if($uid === null || $uid === ""){		die("uid required");	}	@$uname = $_REQUEST['uname'];	if($uname === null || $uname === ""){		die("uname required");	}	@$upwd = $_REQUEST['upwd'];	if($upwd === null || $upwd === ""){		die("upwd required");	}	@$email = $_REQUEST['email'];	if($email === null || $email === ""){		die("email required");	}	@$phone = $_REQUEST['phone'];	if($phone === null || $email === ""){		die("phone required");	}	require("init.php");	$sql = "UPDATE xz_user SET uname='$uname',upwd='$upwd',email='$email',phone='$phone' WHERE uid='$uid'";	$result = mysqli_query($conn,$sql);	if($result === false){		echo "操作失败";	}else{		$count = mysqli_affected_rows($conn);		if($count > 0){			echo "影响行数:$count<br/>";			echo "操作成功";		}else if($count == 0){			echo "要更新的记录不存在或者更新前后数据不变或者其他...";		}	}?>
<?php		//查询	@$uname = $_REQUEST['uname'];	if($uname === null || $uname === ""){		die("uname required");	}	require('init.php');	$sql = "SELECT * FROM xz_user WHERE uname='$uname'";	$result = mysqli_query($conn,$sql);	if($result === false){		echo "操作失败";	}else{		//$arr = mysqli_fetch_all($result,MYSQLI_ASSOC);		//$arr = mysqli_fetch_all($result,MYSQLI_BOTH);		$count = mysqli_affected_rows($conn);		echo $count . "<br/>";		if($count > 0){			$arr = mysqli_fetch_all($result,1);			var_dump($arr);		}else{			echo "无查询结果";		}	}?>





以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索php , 代码 删改 ,以便于您获取更多的相关知识。