PHP code example of ponup / sql-builders

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

    

ponup / sql-builders example snippets


$queryBuilder = new InsertQueryBuilder('table');
$queryBuilder->setColumns('foo, bar, baz');

echo $queryBuilder->toSql(); # Prints 'INSERT INTO table (foo, bar, baz) VALUES (?, ?, ?)'

$queryBuilder = new SelectQueryBuilder('foo');
$queryBuilder->setColumns('bar, baz');
$queryBuilder->setLimit('0, 20');
$queryBuilder->setOrderBy('bar DESC');

echo $queryBuilder->toSql(); # Prints 'SELECT bar, baz FROM foo ORDER BY bar DESC LIMIT 0, 20'

$queryBuilder = new UpdateQueryBuilder('person');
$queryBuilder->setColumnValues([
    'email' => 'NULL',
    'age' => 42,
    'weight' => 100,
    'code' => '?'
]);
$queryBuilder->setWhereConditions('id = ?');

echo $queryBuilder->toSql(); # Prints 'UPDATE person SET email = NULL, age = 42, weight = 100, code = ? WHERE id = ?'

$subject = new DeleteQueryBuilder('foo');
echo $subject->toSql(); # Prints 'DELETE FROM foo WHERE id = ?'