TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   MySQL & Databases (http://www.talkphp.com/mysql-databases/)
-   -   MySQLi wierdness? (http://www.talkphp.com/mysql-databases/2744-mysqli-wierdness.html)

delayedinsanity 05-01-2008 05:22 PM

MySQLi wierdness?
 
I just ported everything to MySQLi, and everything else works just fine, but for some reason I'm getting wierdness on this query;

PHP Code:

$q sprintf("UPDATE " TBL_USERS " SET password='%s' WHERE username='%s'"$szPassword$szUsername);
$result $this->mysqli->query($q);
        
echo 
$result->affected_rows;
die; 

The die is in there to debug it... I'm getting this error;

Notice: Trying to get property of non-object in...

$result should be an object. It is in every other mysqli->query I do. Why isn't it here? The query works, it does what it's supposed to do, it just doesn't return $result like it's supposed to. I'm lost.
-m

Wildhoney 05-01-2008 05:35 PM

php Code:
$result = $this->mysqli->query($q);
echo $this->mysqli->affected_rows;

Like that?

delayedinsanity 05-01-2008 05:59 PM

According to the documentation, $result should be an object returned by the query, and the actual location of the variable would be $result->affected_rows. $this->mysqli->affected_rows just returns 0, and $this->mysqli->num_rows doesn't exist (as you're supposed to use $result->num_rows). It works just fine in my other database queries, which is why it's wierding me out that it's not returning $result for this one.

I wound up changing it to;

PHP Code:

$q sprintf("UPDATE " TBL_USERS " SET password='%s' WHERE username='%s'"$szPassword$szUsername);

if (
$this->mysqli->query($q)) {
    return 
1;
} else {
    return 
0;


but I'm still curious as to why that one query won't return an object to $result.
-m

delayedinsanity 05-01-2008 06:07 PM

See, I just ran a test on another function which does this;

PHP Code:

$q sprintf("SELECT password FROM " TBL_USERS " WHERE username='%s'"$szUsername);
$result $this->mysqli->query($q);

echo 
$result->num_rows;
die; 

...and $result is returned as an object like it's supposed to be.

OH DAMN.

Nevermind, I bow down to your genius. You're right, when it's an UPDATE, it returns to the mysqli object, there is no $result object. Geebus.
-m

wGEric 05-01-2008 08:47 PM

For future reference, PHP: mysqli->affected_rows - Manual

delayedinsanity 05-01-2008 08:50 PM

Yeah, I know that now. I was looking for it in mysqli_result. Just started using the whole deal this morning, but I likes, I likes.
-m


All times are GMT. The time now is 05:08 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0