php-sql-query-builder icon indicating copy to clipboard operation
php-sql-query-builder copied to clipboard

placeholders question

Open sinticbolivia opened this issue 7 years ago • 3 comments

Hello Thanks for great work!! But i have a question. Why the query builder returns the SQL string with just place holder and not with values intead I mean $query->where()->equals('id', 100); SELECT * FROM users WHERE id = :v1 and why not SELECT * FROM users WHERE id = 100

Regards,

sinticbolivia avatar Apr 20 '18 04:04 sinticbolivia

I think this is intended. There are a lot of ways to replace the variables with the values. When using PDO you can use something like prepare to replace the variables with the value and when using mysqli you can use something like bind_param. I think it's intended to let the user define the way to replace it and the library is not tightly coupled to an implementation.

oscarteg avatar Jul 20 '18 13:07 oscarteg

Yeah I've been wondering about that myself @sinticbolivia And even after you use prepare and bind_param it still doesn't give you the sql query with the values inserted. This feature will be good for debugging purposes @Oscarteg

marcus-hiles avatar Mar 29 '19 11:03 marcus-hiles

I added a pull request (#109) that addresses this issue. Maybe I got the mechanism all wrong but maybe it helps you.

EDIT: never mind, I used the software wrong...

$s = $builder->select()->setTable('test')->where()->equals("id", $someID)->end();
$pdo->prepare($s);
$pdo->execute($builder->getValues());
$r = $pdo->fetchAll();

That's about the way to go, I guess...

nitricware avatar Jul 21 '19 11:07 nitricware