Page 1 of 1

mysql_query() return

Posted: Tue Aug 09, 2005 4:02 pm
by Ree
What will the echo print

Code: Select all

function Query($query)
  {
    $rs = mysql_query($query);
    if ($rs === false)
    {
      return false;
    } else
    if ($rs === true)
    {
      return true;
    } else
    {
      $result_set = new ResultSet($rs);
      return $result_set;
    }

$var = Query($query);
echo $var;
if $query is:

1. Non-empty SELECT query.
2. Empty SELECT query.

I would say:

1. Object.
2. False.

But I get Object in both cases. How come?

Posted: Tue Aug 09, 2005 4:09 pm
by feyd
any empty result set isn't a failure. It simply means you didn't find any records that matched.

Both should be objects.

Posted: Tue Aug 09, 2005 4:12 pm
by Ree
ooh yes, now I see I have misinterpreted one of the comments on the mysql_query() page on PHP.net. My bad! :)

http://lt.php.net/manual/en/function.mysql-query.php
If the query was empty, returns false.
:P

Posted: Tue Aug 09, 2005 4:28 pm
by feyd
yeah.. that was from a user created comment, about his function he was posting..