zacharyrankin/named-sql-params

Named parameters in sql strings

v0.1 2015-08-21 00:41 UTC

This package is not auto-updated.

Last update: 2024-03-20 07:27:21 UTC


README

Named parameters in sql strings

Usage

$named = new NamedSqlParams;
$sql = <<<SQL
SELECT
    id,
    username,
    email
FROM :!users_table
WHERE country = :country
    AND gender IN (:genders)
SQL;
$params = [
    'users_table' => 'users',
    'country'     => 'USA',
    'genders'     => ['M', 'F']
];

list($prepared_sql, $prepared_params) = $named->prep($sql, $params);

// $prepared_sql will be:
// SELECT
//     id,
//     username,
//     email
// FROM users
// WHERE country = ?
//     AND gender IN (?, ?)

// $prepared_params will be:
// ['USA', 'M', 'F']

TODO

  • More documentation
  • Refactor code some more
  • Push to packagist