auraphp/Aura.SqlQuery

Named placeholder don't work in where()

Opened this issue · 1 comments

The documentation in examles allow to used named placeholders in where clause like this:

// bind 'zim_val' to the :zim placeholder
->where('zim = :zim', ['zim' => 'zim_val'])

But this will not work since named placeholders don't update bind_values internal property. The ->where() method only works with ?-placeholders which actually not documented at all. I've lost 2 hours trying to figure it out.

$select = $queryFactory->newSelect()->cols(['*'])->from('table1')->where('col1 = :col1', ['col1' => 'value']);
var_dump($select->getStatement());
var_dump($select->getBindValues());

This will print SQL query and empty array of bind values.

Possible workaround could be using of additional bindValues():

$select = $queryFactory->newSelect()->cols(['*'])->from('table1')->where('col1 = :col1')->bindValues(['col1' => 'value']);
var_dump($select->getStatement());
var_dump($select->getBindValues());

or using ?-placeholder:

$select = $queryFactory->newSelect()->cols(['*'])->from('table1')->where('col1 = ?', 'value');
var_dump($select->getStatement());
var_dump($select->getBindValues());

But both variants looks dirty and not match documentation.

P.S. Is this repo abandoned?

I am assuming you are using 3.x and this is related to the PR #142 .