Displaying MySQL Error for Long Queries with User Input in PHP
In PHP, executing lengthy MySQL queries dependent on user input can result in failures. However, the generic error message "Query Failed" provides insufficient information for troubleshooting. To display the specific error message, consider the following solutions:
Solution 1:
Modify your query execution line to include error handling:
mysqli_query($this->db_link, $query) or die(mysqli_error($this->db_link)); // Error handling added
Solution 2:
You can append the following line after the query execution:
if ($r == false) printf("error: %s\n", mysqli_errno($this->db_link));
Additional Notes:
The above is the detailed content of How Can I Display Specific MySQL Error Messages for Long Queries with User Input in PHP?. For more information, please follow other related articles on the PHP Chinese website!