According to PHP documenation for mysql_query():
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
resultset, mysql_query() returns a resource on success, or FALSE on
error.For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc,
mysql_query() returns TRUE on success or FALSE on error.
If SELECT returns a resource on succes, does it actually return TRUE on succes? So is it still valid to do?:
<?php
$result = mysql_query('SELECT * WHERE 1=1');
if ($result) {
//resultset is valid?
}
?>
I’m almost sure it does, but how does that work? Does mysql_query() just returns several properties?
From the PHP manual entry on booleans:
The emphasis is mine, but applies to your situation.
Also, do not use the
mysql_*functions in your code. These functions are no longer maintained and are being deprecated. Instead, you should use either MySQLi or PDO. Don’t know which to use? This article should help.