Coly010 Posted July 23, 2013 Posted July 23, 2013 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 :) Quote
KyleMassacre Posted July 23, 2013 Posted July 23, 2013 not to sound stupid or nothing but did you create a function called num_rows() in your class? Could you have misspelled it somewhere, maybe called it numrows()? Quote
Guest Posted July 23, 2013 Posted July 23, 2013 num_rows isn't a built in function when using mysqli in an object oriented way. Use http://uk3.php.net/mysqli_num_rows for reference. Quote
Barrikor Posted July 23, 2013 Posted July 23, 2013 (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 July 23, 2013 by Barrikor Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.