Debugging SQL in MySQLi

suggest change

So your query has failed (see http://stackoverflow.com/documentation/php/2784/php-mysqli/9380/mysqli-connect for how we made $conn)

$result = $conn->query('SELECT * FROM non_existent_table'); // This query will fail

How do we find out what happened? $result is false so that’s no help. Thankfully the connect $conn can tell us what MySQL told us about the failure

trigger_error($conn->error);

or procedural

trigger_error(mysqli_error($conn));

You should get an error similar to

Table ‘my_db.non_existent_table’ doesn’t exist

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents