PHP code example of brunogasparetto / query-builder

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

    

brunogasparetto / query-builder example snippets


$database = new QueryBuilder\Database([
    'driver'   => 'mysql',
    'charset'  => 'utf8',
    'host'     => 'localhost',
    'dbname'   => 'databaseName',
    'user'     => 'user',
    'password' => 'password',
    'fetchMode' => PDO::FETCH_OBJ, // Default
]);

$query = $database
    ->select('column')
    ->from('table')
    ->whereOpen()
        ->where('column1', '=', 5)
        ->where('column2', '=', 'Name')
    ->whereClose()
    ->whereOrOpen()
        ->where('column1', '=', 10)
        ->where('column2', '=', 'Other Name')
    ->whereOrClose();

echo (string) $query;

$query
    ->select('coluna2', 'coluna3')
    ->join('tabela2')
        ->on('table.id', '=', 'tabela2.id')
        ->on('userid', '=', 5)
    ->where('tabela2.coluna2', '=', true);

echo (string) $query;