PHP code example of shasoft / sql-query-builder

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

    

shasoft / sql-query-builder example snippets


    // Создать построитель запросов
    $builder = new Builder(
        // PDO драйвер соединения с БД
        \PDO $pdo,
        // Состояние БД
        StateDatabase $stateDatabase
    );
    // Сгенерировать и выполнить запрос
    $builder->select(User::class, ['id', 'name'])
        ->where(function (Where $where) {
            $where
                ->cond('id', '>', 1)
                ->inSelect(
                    ['id', 'name'],
                    UserInfo::class,
                    ['id', 'description']
                );
        })
        ->join(function (Join $join) {
            $join->left(Article::class, 
                ['userId' => 'id'], 
                ['sum(rate) as rate'])
                ->having('SUM(rate)', '>', 100);
        })
        ->limit(2)->orderBy('name')
        ->groupBy('id')->groupBy('name')
        ->get();