peteraba / foo-pdo
Pdo statement preprocessors (e.g. easy IN () where clauses)
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/peteraba/foo-pdo
Requires (Dev)
- phpunit/phpunit: ^6.1
This package is auto-updated.
Last update: 2021-03-09 14:06:21 UTC
README
Pdo statement preprocessors (e.g. easy IN () where clauses)
Setup
Install the library via composer:
composer install peteraba/foo-pdo
Usage
Usage by unnamed parameters:
$sql = 'SELECT name, age, salary FROM employee WHERE age > ? AND department_id IN (?)'; $departmentIds = [3, 4, 6]; $minAge = 40; $parameters = [$minAge, $departmentIds]; $preprocessor = (new \Foo\Pdo\Statement\Preprocessor\Factory())->getPreprocessor(); $preprocessor->process($sql, $parameters); // $sql = 'SELECT name, age, salary FROM employee WHERE age > ? department_id IN (?, ?, ?)' // $departmentIds = [40, 3, 4, 6];
Usage with named parameters:
$sql = 'SELECT name, age, salary FROM employee WHERE age > :age AND department_id IN (:departmentIds)'; $departmentIds = [3, 4, 6]; $minAge = 40; $parameters = [$minAge, $departmentIds]; $preprocessor = (new \Foo\Pdo\Statement\Preprocessor\Factory())->getPreprocessor(); $preprocessor->process($sql, $parameters); // $sql = 'SELECT name, age, salary FROM employee WHERE age > :age department_id IN (:departmentIds__expanded0, :departmentIds__expanded1, :departmentIds__expanded2)' // $departmentIds = [ 'age' => 40, 'departmentIds__expanded0' => 3, 'departmentIds__expanded1' => 4, 'departmentIds__expanded2' => 6, ];
Note: The current implementation is able to handle a mixed set of named and unnamed parameters, but there is no guarantee for this to be the case in the future so you should avoid using this unsupported feature.