<?php
$mysql_server_name="localhost"; //数据库服务器名称
$mysql_username="root"; // 连接数据库用户名
$mysql_password="111111"; // 连接数据库密码
$mysql_database="test"; // 数据库的名字
$mysql_prot = "3306";
$mysqli = new mysqli($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);
if($mysqli){
echo "mysqli success"."<br>";
}else{
echo "mysqli error"."<br>";
}
$query = "select * from user";
//查询name字段
$sql1 = "select * from user WHERE id = 0";
//插入数据
$sqlInsert = "insert into user (id,name) values('6','hah')";
//删除数据
$sqldelete = "delete from user where id = 6";
//修改数据
//$sqlUpdate = "update user set name = 'weizhi2' where name = 'iceboy'";
$sqlUpdate = "update user set id = 5 where id = 0";
// $res = $mysqli->query($sql1);
// $res = $mysqli->query($sqlInsert);
//$res = $mysqli->query($sqldelete);
$res = $mysqli->query($sqlUpdate);
echo $mysqli->affected_rows;
if($res){
echo "query success"."<br>";
// 三种处理查询结果
//喜欢使用后面两种方法
// 方法一
// while(list($id,$name)=$res->fetch_row()){
// echo "id: ".$id." name:".$name."<br>";
// }
// 方法二
// while($row = $res->fetch_object()){
// echo "id:".$row->id." name:".$row->name."<br>";
//
// }
//方法三
// while ($row = $res->fetch_assoc()){
// echo "id:".$row["id"]." name:".$row["name"]."<br>";
// }
}else{
echo "query error"."<br>";
}
//$res->free();
$mysqli->close();
?>