Skip to content
This repository has been archived by the owner on Mar 6, 2021. It is now read-only.
/ FooPdo Public archive

Pdo statement preprocessors (e.g. easy IN () where clauses)

Notifications You must be signed in to change notification settings

peteraba/FooPdo

Repository files navigation

FooPdo

Pdo statement preprocessors (e.g. easy IN () where clauses)

Build Status License composer.lock Scrutinizer Code Quality Code Coverage Build Status

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.

About

Pdo statement preprocessors (e.g. easy IN () where clauses)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages