mysql_query() return

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

mysql_query() return

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post 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
Last edited by Ree on Tue Aug 09, 2005 4:58 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yeah.. that was from a user created comment, about his function he was posting..
Post Reply