Skip to content
Advertisement

mysql_query returns TRUE for SELECT statement [closed]

The executing script does mostly nothing but call the following function. This problem doesn’t happen if I am not inserting anything beforehand (and just select the entire table).

JavaScript

This gives the following output:


SELECT * FROM authors WHERE id = 27 LIMIT 1;
$result: true
Number of selected rows: 1
Error:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in file_path.php on line 89 null


Using a different SQL client, the above SELECT query returns a row. I am using PHP 5.3.3.

The “duplicate” questions don’t seem to answer the question.

Before the anti-mysql_* bandwagon rolls around the corner, I am using a server in which I have no control over for a school project. The server is controlled by the IT department. The pdo_mysql and mysqli extensions are not installed. Additionally, there are no other SQL extensions enabled except for the sqlite extension (which wouldn’t suffice since I need to use foreign keys). And the system administrator will not make changes. The point is that I have no choice but to use the mysql_* functions.

Advertisement

Answer

Using the || operator converts the result to a boolean value.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement