php-mysqlHow to get query error message in PHP MySQL?
To get the query error message in PHP MySQL, you can use the mysqli_error() function. This function returns the error message from the last MySQL operation.
Example code
$mysqli = new mysqli("localhost", "user", "password", "database");
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
$query = "SELECT * FROM table";
$result = $mysqli->query($query);
if (!$result) {
    printf("Error: %s\n", mysqli_error($mysqli));
    exit();
}
Output example
Error: Table 'database.table' doesn't exist
Code explanation
mysqli_error(): This function returns the error message from the last MySQL operation.mysqli_connect_errno(): This function returns the error code from the last MySQL operation.mysqli_connect_error(): This function returns the error message from the last MySQL connection error.
Helpful links
More of Php Mysql
- How to check the result of an insert in PHP and MySQL?
 - How to output XML from MySQL using PHP?
 - How to get the version of MySQL using PHP?
 - How to connect to a MySQL database using PHP?
 - How to store a boolean value in a MySQL database using PHP?
 - How to list tables in PHP MySQL?
 - How to write an update query in MySQL using PHP?
 - How to get the last insert ID in PHP MySQL?
 - How to update to null value in MySQL using PHP?
 - How to use a MySQL union in PHP?
 
See more codes...