简体   繁体   中英

Weird bug with PHP / Mysql mysql_query and mysql_fetch_object

I have an issue and I don't understand what's happening. I have a mysql query that works perfectly. It's supposed to return a row in a table.

$res = mysql_query($query);     
$myobj = mysql_fetch_object($res);

When I do :

var_dump($myobj);

It returns:

object(stdClass)#3 (25) { ["id"]=> string(2) "10" ["cookie"]=> string(3) "yes" ["nb_pts_per_question"]=> string(2) "50" ["product"]=> string(10) "MyProduct" } bool(false)

The object sounds complete but at the end of the var_dump you can see a bool(false)

Again, the query works fine when I run it into mysql.

Any idea?

Thanks!

Looks like a stray var_dump . Don't you put your var_dump in a while loop ? That would explain the bool (false)

That is indeed a little strange...

Just by curiosity, what output is giving print_r($myobj) ?

In the end, does using your object work?

As you are using mysql_fetch_object() thats why u are getiing this result, please see this link http://php.net/manual/en/function.mysql-fetch-object.php . You can use mysql_fetch_assoc()

The bool(false) value is there are no more data indicator See in this link it says that

Return Values

Returns an object with string properties that correspond to the fetched row,  
or FALSE if there are no more rows. 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM