面向对象风格
<?php
$conn = new mysqli("localhost", "username", "password", "database_name");
if($conn->connect_errno) {
printf("connect filed: $s \n", $conn->connect_error);
exit;
}
if(!$conn->query("SET a=1")) {
printf("error message: %s\n", $conn->error);
}
?>
面向过程风格
<?php
$conn = mysqli_connect("localhost", "username", "password", "database_name");
if(mysqli_connect_errno()) {
printf("connect filed: $s \n", mysqli_connect_error);
exit;
}
if(!mysqli_query($conn, "SET a=1")) {
printf("error message: %s\n", mysqli_error($link));
}
?>
From: http://php.net/manual/zh/mysqli.error.php