1 增删改查
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<?php
$servername="127.0.0.1";
$username="root";
$password="123123";
$dbname="test";
//创建连接
$conn=new mysqli($servername,$username,$password,$dbname);
if($conn->connect_error){
die("连接失败".$conn->connect_error);
}
echo "连接成功";
//添加
/* $sqladd="INSERT INTO user(name,password) VALUES('123','123')";
//执行添加
mysqli_query($conn, $sqladd); */
//删除
/* $sqldelete="delete from user where id=1";
mysqli_query($conn, $sqldelete);
echo "删除成功"; */
//更新
$sqlUpdate="update user set name=111 where password='123'";
mysqli_query($conn, $sqlUpdate);
echo "<br>更新成功";
//查询
/* $sql="select * from user";
$result=$conn->query($sql);
foreach ($result as $row){
echo "id:".$row["id"]."name".$row["name"]."password".$row["password"]."<br>";
}
echo "查询成功";
*/
mysqli_close($conn);
?>
</body>
</html>