Fatal error: Uncaught Error: Call to a member function fetchAll() on boolean in

0 votes
asked Sep 25, 2016 in PHP Frameworks by mdasduzzamanrony (120 points)

//File Name: index.php

<?php
include_once "system/libs/main.php";
include_once "system/libs/dcontroller.php";
include_once "system/libs/r_model.php";
include_once "system/libs/database.php";
include_once "system/libs/load.php";

$url     = isset($_GET['url']) ? $_GET['url']:NULL;  // this is Super Global get method
if($url!=NULL){
    $url     = rtrim($url, '/');                         // This is avoid jest for '/' of array index
    $url     = explode("/", $url);                       // This is libary function of php main. that work just work with array
}else {
    unset($url);
}


if(isset($url[0])){
    include 'app/controllers/'.$url[0].'.php';
    $ctlr = new $url[0]();
    if (isset($url[2])) {
        $ctlr->$url[1]($url[2]);
    }  else {
        if(isset($url[1])){
            $ctlr->category();
        }  else {
            //code
        }

    }
}  else {
    include 'app/controllers/wellcome.php';
    $ctlr = new wellcome();
    $ctlr->home();
}

File name: wellcome.php

<?php

/* 
 *Wellcome is file of index controller
 */
class wellcome extends dcontroller {
    function __construct() {
        parent::__construct();
    }
    public function home(){
        //$this->load->view("home");

    }
    public function category(){
        $data        = array();
        $cat_model   = $this->load->model("cat_model");
        $data['cat'] = $cat_model->cat_list();
        $this->load->view("category", $data);
    }
}

File name: cat_model.php

<?php

/* 
 * This is Catagoris model
 */
class cat_model extends r_model{
    function __construct() {
        parent::__construct();
    }
    public function cat_list(){
        $sql    = "select * from category";
        $query  = $this->db->query($sql);
        $result = $query->fetchAll();
        return $result;
    } 
}

File Name: category.php

<?php

/* 
 * Catagory file 
 */

?>

Category list <hr>
<?php
foreach ($data as $value){
    echo $value['name']."<br/>";
}

File Name: load.php

<?php

/* 
 * Load is Main class
 */

class load {
    public function __construct() {

    }
     public function view($file_name, $data = false){
         if($data = true){
             extract($data);
         }
         include 'app/views/'.$file_name.'.php';
        }
     public function model($model_name){
         include 'app/models/'.$model_name.'.php';
         return new $model_name();
        }
}

File Name: r_model.php

<?php

/* 
 * R_Model is a main model
 */
class r_model{
    protected $db = array();
            function __construct() {
                $this->db = new database();
    }
}

File Name: database.php

<?php

/* 
 * Database for connetion of maney database
 */
class database extends PDO{
    public function __construct() {
        $dsn  = 'mysql:dbname = db_mvc; host = localhost';
        $user = 'root';
        $pass = '';
        parent::__construct($dsn,$user,$pass);
    }

}

File Name: dcontriller.php

<?php

/* 
 * DController Is a Main Controller
 */

class dcontroller {
    protected $load = array();
    public function __construct() {
        $this->load = new load();
    }
}

1 Answer

0 votes
answered Sep 26, 2016 by sakilorb (5,170 points)

please mention full error code that shows on your IDE or Code Editor

722 questions

657 answers

179 comments

4,937 users

Welcome to IDB Scholars Forum, where you can ask questions and receive answers from other members of the community. It's 100% free.
আইডিবি স্কলারস ফোরামে আপনাকে স্বাগত - প্রোগ্রামিং, ডিজাইন, ডেভেলপমেন্ট, ব্লগিং, ইন্টারনেটসহ তথ্য প্রযুক্তির যাবতীয় বিষয় নিয়ে আলোচনার একটি মুক্ত মঞ্চ হলো এই ফোরাম । এখানে আইসিটি বিষয়ক আপনার প্রশ্ন, উত্তর এবং অভিজ্ঞতা শেয়ার করুন, আলোচনা করুন এবং সমাধান নিন। দেশের তরুণ প্রজন্মকে আইসিটিতে আগ্রহী করাই আমাদের মূল লক্ষ্য।
** ইংলিশ বা বাংলা যে কোনো ভাষায় আপনি এই ফোরামে আলোচনা করতে পারবেন। তবে বাংলাকে ইংরেজি অক্ষরে লিখবেন না।
  1. month7jeff

    100 points

    0 answers

  2. PrincessVill

    100 points

    0 answers

  3. recess8hip

    100 points

    0 answers

  4. editorsong1

    100 points

    0 answers

  5. KaiSilva2538

    100 points

    0 answers

...