I'm learning PHP and ran into something I can't quite figure out if what I am doing is really the way I should or if there is a better way. Here's an example.
If I use this code to get information and display the results:
$time = mysqli_query($link, "SELECT UNIX_TIMESTAMP()");
print $time;
My browser returns Object id #3 (I'm running PHP through Apache2).
But, if I use this code:
$time = mysqli_query($link, "SELECT UNIX_TIMESTAMP()");
while ($row = mysqli_fetch_array($time)) {
print $row[0];
}
I get the actual result of (i.e., the content of the object held by $time) the SELECT statement to print to the browser which is what I want.
I understand from the online PHP manual (see http://us3.php.net/mysqli_query) that mysqli_result will return a result object (hence the reason for the "Object id #3" message?), but then it goes on to say the "resultmode" is mysqli_use_result or mysqli_store_result. I read about these in the online PHP manual and am confused.
I've been reading the SAMS Teach Yourself "PHP, MySQL, and Apache" book and cannot find any detailed explanation as to:
1. What is the best way to print the results of a mysqli_query to a browser (I seriously doubt the above method I am currently using is the best). I have no problem understanding why using my above method might be appropriate when I have multiple rows of data being returned, but to do this when I know that only a single row, with one item, will be returned seems odd.
2. How do you use MYSQLI_USE_RESULT and MYSQLI_STORE_RESULT? Every Google search I do pretty much points me to a copy of what the online PHP manual says with no further explanation.
Also, could somebody please recommend a more comprehensive book than the SAMS book I am reading?
Thanks.
TC