Jump to content
MakeWebGames

Object Oriented Mysqli Connection Problem


Recommended Posts

Posted

Ok, so I've gone the OOP approach to connecting to my mysql database, and thus my variable is $db.

now my problem is that when I try to run this code

$sql = $db->query("SELECT * FROM users WHERE (username = '$username' & password = '$epassword')");
$nr = $db->num_rows($sql);

 

i get this error : Fatal error: Call to undefined method mysqli::num_rows() in C:\xampp\htdocs\chat\au.php on line 16

I do not know what what is wrong with how I called the method, can anyone point it out? I'd be really appreciative.

Thanks :)

Posted (edited)
Ok, so I've gone the OOP approach to connecting to my mysql database, and thus my variable is $db.

now my problem is that when I try to run this code

$sql = $db->query("SELECT * FROM users WHERE (username = '$username' & password = '$epassword')");
$nr = $db->num_rows($sql);

 

i get this error : Fatal error: Call to undefined method mysqli::num_rows() in C:\xampp\htdocs\chat\au.php on line 16

I do not know what what is wrong with how I called the method, can anyone point it out? I'd be really appreciative.

Thanks :)

 

OO Mysqli actually has more than one object, you just need to call num_rows from the result object instead of the db object:

 


$result_handle = $db_handle->query("SELECT * FROM users WHERE (username = '$username' & password = '$epassword')");
if($result_handle)
{
$result_handle->store_result(); // if all you're doing is getting num_rows
$nr = $result_handle->num_rows;

//note that num_rows will screw up until you run though every fetch or use store_result or anything that does the same. 
}
else
{
//stuff for if query failed
}
Edited by Barrikor

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...