inglar / sql-builder
1.0.3
2017-01-27 15:47 UTC
Requires
- php: >=5.5.3
Requires (Dev)
- phpunit/phpunit: ^4.8 || ^5.1
This package is not auto-updated.
Last update: 2025-02-01 22:02:54 UTC
README
Composer
Open a command console, enter your project directory and execute the following command to download the latest stable version of this package:
$ composer require inglar/sql-builder
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Supported Adapters
SqlBuilder supports the following database adapters:
- MySQL (specify mysql)
- PostgreSQL (specify pgsql)
Usage
Simple select
$builder = new SqlBuilder('pgsql'); $select = $builder->select() ->column('*') ->from('table') ->where('id = :id') ->bindParam(':id', 123); echo $select; print_r($select->getBindParams());
The above example will output:
SELECT * FROM "table" WHERE id = :id
Array
(
[:id] => 123
)
Select with join
$builder = new SqlBuilder('pgsql'); $select = $builder->select() ->column('*') ->from('table') ->join($builder->join('table2', "table2.user_id = table.id") ->where('id = :id') ->bindParam(':id', 123); echo $select; print_r($select->getBindParams());
The above example will output:
SELECT * FROM "table" JOIN "table2" ON table2.user_id = table.id WHERE id = :id
Array
(
[:id] => 123
)