Echoing MySQL Response's Resource ID #6 in PHP
When querying a database using the MySQL extension in PHP, you may encounter the "Resource id #6" output instead of the intended result. This occurs because the query returns a resource, not a string or numeric value.
Echoing the Result
To display the intended result, you must first fetch the data using one of the provided fetch functions. One such function is mysql_fetch_row(), which retrieves a row of data as an array of values.
Example Code
Here's an example that demonstrates how to fetch and echo the result:
$datos1 = mysql_query("SELECT TIMEDIFF(NOW(), '" . $row['fecha'] . "');");
$data = mysql_fetch_row($datos1);
if ($data !== false) {
echo $data[0];
}
This code will fetch the first row of the result and echo the first column's value, which should be the time difference between the current time and the specified fecha value.
Note on MySQL Extension
It's important to note that the mysql extension is no longer recommended for use in new projects. Instead, you should use PDO (PHP Data Objects) with the PDO_mysql adapter or the mysqli extension.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3