tommyknocker / pdo-database-class

PHP PDO Wrapper which utilizes PDO and prepared statements
GNU Lesser General Public License v3.0
68 stars 46 forks source link

Fatal error: Call to a member function execute() on null #7

Open usmanawaan opened 5 years ago

usmanawaan commented 5 years ago

When i open a link localhost/web/newpanel/auth/login the below error shown please tell me what's wrong in my code please check below error and my files.

Fatal error: Call to a member function execute() on null in F:\Ampps\www\web\newpanel\Application\Libs\PDODb.php on line 972

Directory Structure Application -Controllers --Auth.php -Core --Modal.php -Libs --PDODb.php -Modals --AuthModal.php

My Application use SplAutoload function for autoload classes

/** Application/Controllers/Auth.php file start ***/

<?php
namespace Application\Controllers;
use \Application\Models\AuthModel;
class Auth extends MainController
{
    function __construct($root_params="")
    {
        parent::__construct();
        $this->authModel = new AuthModel();
        $this->root_params = $root_params;
    }
    public function login()
    {

        $data = $this->authModel->selectAll();
        var_dump($data);
        exit;

    }
}

/** Application/Controllers/Auth.php file end ***/

/** Application/Modals/AuthModal.php file start ***/

<?php
namespace Application\Models;
use \Application\Core\Model as MainModel;
class AuthModel extends MainModel
{
    public function __construct(){
        $this->table = "users";
    }
}

/** Application/Controllers/Auth.php file end ***/

/** Application/Core/Modal.php file start ***/

<?php
namespace Application\Core;
use \Application\Libs\PDODb;
class Model
{
    private static function getDB()
    {

        $db = new PDODb('mysql','localhost', 'root', 'mysql', 'newpanel');
        return $db; 

    }

    public function selectAll()
    {
        $db = static::getDb();
        $result = $db->get("activitylog");

        return $result;
    }
}

/** Application/Core/Modal.php file end ***/