1. Go to this page and download the library: Download hasan-22/query-builder library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class Mysql implements \App\Database\ConnectionInterface
{
private static $instance;
private function __construct(){}
/**
* This method prevents the creation of duplicate object
* @return mixed
*/
public static function setInstance(){
if(!static::$instance instanceof Mysql){
static::$instance = new Mysql();
}
return static::$instance;
}
/**
* Get database connection information in configuration
* @return array
*/
public function driver(): array{
/**
* If you have set the database in the config file, use this code.
*/
// Path of your config file
$config = ATURAL
];
return \App\Database\PDO::connect($this->driver(),$attributes);
}
}
$db->table('users')->find()
// or
$db->table('users')->find(1,2,3)
$db->table('users')->where('name','=','armia')->get();
// for `or where`
$db->table('users')->orWhere('name','=','armia')->get();
// for `where in`
$db->table('users')->whereIn('id',[1,2,3])->get();
// for `or wher in`
$db->table('users')->orWhereIn('id',[1,2,3])->get();
// for `where between`
$db->table('users')->whereBetween('crated_at',['2022-12-12','2023-01-29'])->get();
// for `or where between`
$db->table('users')->orWhereBetween('crated_at',['2022-12-12','2023-01-29'])->get();
// for `exists`
$db->table('brands')->exists('users','users.id = brands.user_id')->get();
// And you can run all the functions one after the other like the example below
$db->table('users')
->where('name','=','armia')
->orWhere('name','=','armia')
->whereIn('id',[1,2,3])
->orWhereIn('id',[1,2,3])
->whereBetween('crated_at',['2022-12-12','2023-01-29'])
->orWhereBetween('crated_at',['2022-12-12','2023-01-29'])
->get()
$db->table('users')->havin('name','=','armia')->get();
// for `or where`
$db->table('users')->orHaving('name','=','armia')->get();
// for `where in`
$db->table('users')->havingIn('id',[1,2,3])->get();
// for `or wher in`
$db->table('users')->orHavingIn('id',[1,2,3])->get();
// for `where between`
$db->table('users')->havingBetween('crated_at',['2022-12-12','2023-01-29'])->get();
// for `or where between`
$db->table('users')->orHavingBetween('crated_at',['2022-12-12','2023-01-29'])->get();
// And you can run all the functions one after the other like the example below
$db->table('users')
->having('name','=','armia')
->orHaving('name','=','armia')
->havingIn('id',[1,2,3])
->orHavingIn('id',[1,2,3])
->havingBetween('crated_at',['2022-12-12','2023-01-29'])
->orHavingeBetween('crated_at',['2022-12-12','2023-01-29'])
->get()
$db->table('users')->where('id','=',1)->update(['name'=>'update name','email'=>'[email protected]']);
// or
$db->table('users')->update(['name'=>'update name','email'=>'[email protected]'],['id'=>1]);
// or
$db->table('users')->update(['name'=>'update name','email'=>'[email protected]'],['id'=>1,'status'=>'activated']);
$db->table('users')->where('id',1)->delete();
// or
$db->table('users')->delete(['id',1]);
// or
$db->table('users')->delete(['id',1,'status'=>'activated']);