Skip to content

Random named placeholders

Latest
Compare
Choose a tag to compare
@bpolaszek bpolaszek released this 22 Jul 11:04

To avoid conflicts with existing placeholders into the same query, we added support for random named placeholders in field helpers. They can be simply enabled by passing ?? as the $placeholder argument.

Examples:

use function BenTools\Where\field;

$condition = field('foo')->equals('bar');
echo $condition; // "foo = ?"
var_dump($condition->getValues()); // ['bar']

$condition = field('foo')->equals('bar', null);
echo $condition; // "foo = bar"
var_dump($condition->getValues()); // []

$condition = field('foo')->equals('bar', 'baz');
echo $condition; // "foo = :baz"
var_dump($condition->getValues()); // ['baz' => 'bar']

$condition = field('foo')->equals('bar', '??');
echo $condition; // "foo = :pbdnsvvx"
var_dump($condition->getValues()); // ['pbdnsvvx' => 'bar']

$condition = field('foo')->in(['bar', 'baz']);
echo $condition; // "foo IN (?, ?)"
var_dump($condition->getValues()); // ['bar', 'baz']

$condition = field('foo')->in(['bar', 'baz'], '??');
echo $condition; // "foo IN (:qifhdhff, :rqxshnae)"
var_dump($condition->getValues()); // ['qifhdhff' => 'bar', 'rqxshnae' => 'baz']