PHP code example of ridaamirini / phpquerybuilder

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

    

ridaamirini / phpquerybuilder example snippets


QueryBuilder::create()->select('article')
                      ->where('published_at > ?', 1)
		      ->orderBy('published_at DESC')
		      ->limit(5)
		      ->getQuery();

$query = QueryBuilder::create()->select('article')
                               ->leftJoin('user ON user.id = article.user_id')
                               ->select('user.name')
                               ->getQuery();

$query = QueryBuilder::create()->select('article')->leftJoin('user')->select('user.name')->getQuery();

$query = QueryBuilder::create()->select('article')->select('user.name')->getQuery();

$query = QueryCollection::create()->select('article')->where('id', 1)->getQuery();
// or shortly if you select one row by primary key
$query = QueryCollection::create()->from('user', 1)->getQuery();

$values = ['title' => 'article 1', 'content' => 'content 1'];
$query = QueryCollection::create()->insert('article')->values($values)->getQuery();
// or shortly
$query = QueryCollection::create()->insert('article', $values)->getQuery();

$set = ['published_at' => new QueryBuilderLiteral('NOW()')];
$query = QueryCollection::create()->update('article')->set($set)->where('id', 1)->getQuery();
// or shortly if you update one row by primary key
$query = QueryCollection::create()->update('article', $set, 1)->getQuery();

$query = QueryCollection::create()->delete('article')->where('id', 1)->getQuery();
// or shortly if you delete one row by primary key
$query = QueryCollection::create()->delete('article', 1)->getQuery();



use App\Builder\QueryBuilder;
use App\Schema\QueryCollection;

$collection = new QueryCollection();

//SELECT
QueryCollection::create()->select('article')->where('id', 1)->collect($collection);

//INSERT
$values = ['title' => 'article 1', 'content' => 'content 1'];
$query = QueryCollection::create()->insert('article')->values($values)->collect($collection);

//UPDATE
$set = ['published_at' => 'yesterday'];
$query = QueryCollection::create()->update('article')->set($set)->where('id', 1)->getQuery();

//DELETE
QueryCollection::create()->delete('article')->where('id', 1)->collect($collection);

return $collection;