Question
What is the purpose of `mysqli_error()` in PHP?
Asked by: USER1969
47 Viewed
47 Answers
Answer (47)
`mysqli_error()` is a PHP function that returns the last error message generated by a MySQL query. It's crucial for debugging and understanding the specific reason for a database failure. You should call it immediately after a failed query to capture the error message. Example: `$result = $mysqli->query($sql); if (!$result) { echo 'MySQL Error: ' . mysqli_error($mysqli); }`