dev-master
9999999-devPdo statement preprocessors (e.g. easy IN () where clauses)
MIT
The Development Requires
by Peter Aba
Wallogit.com
2017 © Pedro Peláez
Pdo statement preprocessors (e.g. easy IN () where clauses)
Pdo statement preprocessors (e.g. easy IN () where clauses), (*1)
Install the library via composer:, (*3)
composer install peteraba/foo-pdo
Usage by unnamed parameters:, (*4)
$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:, (*5)
$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., (*6)
Pdo statement preprocessors (e.g. easy IN () where clauses)
MIT