TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 05-01-2008, 06:22 PM   #1 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default 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
delayedinsanity is offline  
Reply With Quote
Old 05-01-2008, 06:35 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 1,547
Thanks: 72
Wildhoney is on a distinguished road
Default

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

Like that?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
delayedinsanity (05-01-2008)
Old 05-01-2008, 06:59 PM   #3 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

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 is offline  
Reply With Quote
Old 05-01-2008, 07:07 PM   #4 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Old 05-01-2008, 09:47 PM   #5 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 125
Thanks: 0
wGEric is on a distinguished road
Default

For future reference, PHP: mysqli->affected_rows - Manual
__________________
Eric
BlogphpBB
wGEric is offline  
Reply With Quote
Old 05-01-2008, 09:50 PM   #6 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:01 AM.

 
     

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