PHP code example of abdulelahragih / querybuilder

1. Go to this page and download the library: Download abdulelahragih/querybuilder 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/ */

    

abdulelahragih / querybuilder example snippets


$pdo = # your pdo connection
$qb = new \Abdulelahragih\QueryBuilder\QueryBuilder($pdo)
# Now you can start using it 
$result = $qb->table('users')
   ->select('id', 'username', 'phone_number', 'gender')
   ->where('role_id', '=', 1)
   ->join('images', 'images.user_id', '=', 'users.id')
   ->get();

$paginator = $qb->table('users')
   ->select('id', 'username', 'phone_number', 'gender')
   ->where('role_id', '=', 1)
   ->paginate($page, $limit);

$paginator = $qb->table('users')
   ->select('id', 'username', 'phone_number', 'gender')
   ->where('role_id', '=', 1)
   ->simplePaginate($page, $limit);

$result = $qb->table('users')
   ->select('id', 'username', 'phone_number', 'gender')
   ->where(function ($builder) {
       $builder->where('role_id', '=', 1)
           ->orWhere('role_id', '=', 2); 
   })
   ->get();

$result = $qb->table('users')
    ->join('images', function (JoinClauseBuilder $builder) {
        $builder->on('images.user_id', '=', 'users.id');
        // you can use all where variants here
        $builder->where('images.user_id', '=', 1);
    })
    ->get();