Skip to content

Library to ease the dynamic construction of SQL statements in PHP

License

Notifications You must be signed in to change notification settings

Ponup/php-sql-builders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codecov

PHP SQL builders

Simple PHP library to dynamically construct SQL statements.

Usage

composer require ponup/sql-builders

Examples

Insert

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

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

Select

$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'

Update

$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 = ?'

Delete

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

About

Library to ease the dynamic construction of SQL statements in PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages