php - running using xampp error on ubuntu : Fatal error: Call to a member function rowCount() on a non-object -
i'm testing program running using xampp
, windows 7
, when i'm upload server using ubuntu
(mysql
, php
, apache
using apt-get
) it's getting error
fatal error: call member function rowcount() on non-object in /var/www/siarsip/class/user.php on line 56
here code snipped :
function getalluser(){ $query=$this->db1->query("select a.user_id,a.username,a.password,a.nip,a.role,b.category,a.input_date,a.last_update users right join user_categories b on a.role=b.usercat_id order role"); $jml_data=$query->rowcount(); if($jml_data>=1){ $hasil=$query->fetchall(); //line 56 return $hasil; }else{ return $jml_data; } }
i've tried change line 56 :
if(!empty($query) , $jml_data > 0) {
still not working.
update : using @cjriii code, i've update line 56 using :
if(is_object($query))
{ { code here }
}
now there's no error, i've tried login produces same error "fatal error: call member function rowcount() on non-object in /var/www/siarsip/class/user.php on line 74"
function loginuser($username,$password){ $password_md5=md5($password); $query=$this->db1->query("select*from users username='$username' , password='$password_md5'"); if(is_object($query)) { $hasil=$query->rowcount(); //line 74 return $hasil; } }
i've insert code again line 74 if(is_object($query)) {
produces no error. cannot login using username , password works.
need advice bro..
two things:
test if $query object before calling method on it. thats' error comes from.
second, instead of testing !empty($query), try testing is_object($query).
if(is_object($query)) { $jml_data = $query->rowcount(); if($jml_data >= 1) { //rest of code here } else return $jml_data; }
edit:
please check documention on empty(): call may returning valid value empty return false.
http://php.net/empty http://php.net/manual/en/function.is-object.php
Comments
Post a Comment