0

I liked the laravel structure, now I want to create DB class for core php project, So how i can make class for calling this line of code?

DB::table('users')->where("id",1")->get();

Here is the class

Class DB {
    public $table='';
    public $where=array();
    public static function table($table){
        $this->table=$table;
    }
    public function where($field,$value){
        $this->where[$field]=$value;
    }

    public function get(){
        echo "<pre>";
        print_r($this->table);
        print_r($this->where);
        echo "</pre>";
    }
}

 DB::table('users')->where("id","1")->get();

But i am getting following error

Fatal error: Uncaught Error: Using $this when not in object context in DB.php:6
Stack trace:
#0 DB.php(20): DB::table('users')
#1 {main} thrown in DB.php on line 6

Qirel
  • 25,449
  • 7
  • 45
  • 62

0 Answers0