<?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 "无查询结果";
}
}
?>