Forgive me if this is a particularly stupid question!
mysql_query($query)
returns a boolean, but you can also assign it to a variable
$results = mysql_query($query)
and then use the other mysql_ functions to extract data.
Out of curiosity, how does mysq_query($query) act as both a boolean and a data container at the same time? What’s happening “under the hood” during these steps?
(yes, I am a n00b…, please be kind!)
If you notice, when it returns true/false, you can’t use it with the other functions such as
mysql_fetch_assoc().From the
mysql_query()documentation:What happens, is for statements that do not return data, it responds true/false on whether or not the query was successful.
When there is a result set, you will see it returns a MySQL resource. This is a special value that allows PHP to figure out what data set you are talking about. You then pass this resource to other MySQL function to retrieve the data.
See: http://www.php.net/manual/en/language.types.resource.php