auraphp / Aura.SqlQuery

Independent query builders for MySQL, PostgreSQL, SQLite, and Microsoft SQL Server.
MIT License
452 stars 86 forks source link

Named placeholder don't work in where() #193

Open gugglegum opened 2 years ago

gugglegum commented 2 years ago

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?

harikt commented 2 years ago

I am assuming you are using 3.x and this is related to the PR https://github.com/auraphp/Aura.SqlQuery/pull/142 .