PHP code example of girgias / query-builder

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

    

girgias / query-builder example snippets


$query = (new \Girgias\QueryBuilder\Select('demo'))
    ->limit(10, 20)
    ->order('published_date')
    ->getQuery();

$start = new \DateTime('01/01/2016');
$end = new \DateTime('01/01/2017');
$query = (new \Girgias\QueryBuilder\Select('demo'))
    ->select('title', 'slug')
    ->selectAs('name_author_post', 'author')
    ->whereBetween('date_published', $start, $end)
    ->order('date_published', 'DESC')
    ->limit(25)
    ->getQuery();

$query = (new \Girgias\QueryBuilder\Select('demo'))
    ->where('author', '=', 'Alice', 'author')
    ->whereOr('editor', '=', 'Alice', 'editor')
    ->getQuery();

$query = (new \Girgias\QueryBuilder\Update('posts'))
    ->where('id', '=', 1, 'id')
    ->bindField('title', 'This is a title', 'title')
    ->bindField('content', 'Hello World', 'content')
    ->bindField('date_last_edited', (new \DateTimeImmutable()), 'nowDate')
    ->getQuery();

$query = (new \Girgias\QueryBuilder\SelectJoin('comments', 'posts'))
    ->tableAlias('co')
    ->select('co.user', 'co.content', 'p.title')
    ->joinTableAlias('p')
    ->innerJoin('post_id', 'id')
    ->getQuery();
sql
SELECT title, slug, name_author_post AS author FROM demo WHERE date_published BETWEEN '2016-01-01 00:00:00' AND '2017-01-01 00:00:00' ORDER BY date_published DESC LIMIT 25
sql
SELECT * FROM demo WHERE (author = :author OR editor = :editor)