//连接数据库方式1
// $conn = new mysqli('localhost', 'root', 'password', 'test');
//连接数据库方式2
$conn = new mysqli();
$conn -> connect('127.0.0.1', 'root', 'root', 'xc');
//check connection (检查PHP是否连接上MYSQL)
if ($conn -> connect_errno) {
printf("Connect failed: %s\n", $conn->connect_error);
exit();
}
//查询代码
// $sql = "select * from name";
$sql = "insert into name (name) values('谁谁谁啊')";
$query = mysqli_query($conn,$sql);
var_dump($query);
// mysqli_fetch_row 返回数字key
// mysqli_fetch_assoc 返回字段key
// mysqli_fetch_array 多一倍,都有
// 返回数据
// while($row=mysqli_fetch_assoc($query)){
// var_dump($row);
// }
//关闭MySQL连接
$conn -> close();