user3018898
user3018898

Reputation: 31

Call to a member function Count() on a non-object in

index.php

$user= DB::getInstance()->get('users',array('user_id','=','1'));
if(!$user->Count()){
    echo 'No User'; 
}else{
    echo 'User Exists';
}

DB.php

class DB {
    private static $_instance = null;
    private $_pdo,
    $_query, 
    $_error = false,
    $_results,
    $_count = 0;
    public function Count(){
        return $this->_count;
    }
}

get function

class Yapilandirma{
    public static function get($yol = null){
        if($yol){
            $yapilandirma = $GLOBALS['yapilandirma'];
            $yol = explode('/',$yol);
            foreach($yol as $bit){
                if(isset($yapilandirma[$bit])) {
                    $yapilandirma = $yapilandirma[$bit];
                }
            }

            return $yapilandirma;
        }

        return false;
    }   
}

I checked other 15+ topics with same title but i couldn't solve it.need add more detail to post still it wants detail omg.

Upvotes: 0

Views: 2447

Answers (2)

user3610760
user3610760

Reputation: 13

I ran across this tutorial and had the same problem as user had, & I eventually gave up. I worked for a long time on it but was never able to figure it out. If someone wants to take a swing at it I would post the fix to other discussion board and help out a bunch of people. The tutorial is awesome and the system is great but there just seems to be a lingering problem that eventually hangs alot of people up.

http://www.youtube.com/watch?v=PaBWDOBFxDc&list=PLfdtiltiRHWF5Rhuk7k4UAU1_yLAZzhWc

public function count() {

return $this->_count; }

the actual word count is in bold blue..whereas the rest of the function names are in just regular black font. even if you don't want to take the time to look at the videos can some at least tell why that is????? I'm using notepad ++

Upvotes: 0

Barmar
Barmar

Reputation: 781068

Count is a method of the DB class. But you're setting $user to the result of get(), not getInstance().

$instance = DB::getInstance();
$instance->get('users',array('user_id','=','1'));
if (!$instance->Count()) {
    echo 'No user';
} else {
    echo 'User exists';
}

Upvotes: 1

Related Questions