How can the error "mysql_num_rows() expects parameter 1 to be resource, boolean given" be resolved when using mysql_query in PHP?
The error "mysql_num_rows() expects parameter 1 to be resource, boolean given" occurs when the mysql_query function in PHP fails to execute the query and returns a boolean value (false) instead of a resource. To resolve this issue, you should check if the query was executed successfully before using mysql_num_rows() function by verifying the return value of mysql_query.
$result = mysql_query($query);
if($result){
$row_count = mysql_num_rows($result);
// Further processing of the result
} else {
// Handle query execution failure
}
Keywords
Related Questions
- What are common pitfalls when using the PHP Spreadsheet Excel Writer for Excel exports?
- In the context of the forum thread, what are some key differences between the PHP code provided by different users and how do these differences impact the functionality of the code?
- What are the benefits of using a Mailer class or library for email transmission in PHP?