Debugging SQL in MySQLi
suggest changeSo 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
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents