0

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

Background information:

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?

Community
  • 1
  • 1
user1178560
  • 303
  • 1
  • 4
  • 14
  • Please read the doc, before asking simple question: http://it1.php.net/mysql_Query Also don't use mysql_* – dynamic Nov 15 '12 at 00:21
  • @yes123 Where do you think I got the background info from :p. Hmm, I did read the link you showed, and no, that's not my querstion. Thanks anyway :) – user1178560 Nov 15 '12 at 00:22

1 Answers1

2

From the PHP manual entry on booleans:

When converting to boolean, the following values are considered FALSE:

  • the boolean FALSE itself
  • the integer 0 (zero)
  • the float 0.0 (zero)
  • the empty string, and the string "0"
  • an array with zero elements
  • an object with zero member variables (PHP 4 only)
  • the special type NULL (including unset variables)
  • SimpleXML objects created from empty tags

Every other value is considered TRUE (including any resource).

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.

Jonah Bishop
  • 11,967
  • 5
  • 44
  • 72