nilportugues / php-sql-query-builder

An elegant lightweight and efficient SQL Query Builder with fluid interface SQL syntax supporting bindings and complicated query generation.
http://nilportugues.com
MIT License
418 stars 115 forks source link

New placeholder management #109

Closed nitricware closed 5 years ago

nitricware commented 5 years ago

Hy,

I couldn't figure out what the value parameter is used for. So I thought, why not use it for something I need. Maybe someone needs that too. Maybe I use the software all wrong...

The current behaviour is this:

$q = $this->qb->select()->setTable("someTable")->where()->equals("id", 12345)->end();
$s = $this->qb->write($q);
// $s looks like this: SELECT someTable.* from someTable WHERE id = :v1
$s = parent::prepare($s);
// Context: the surrounding class extends PDO
$s->bindValue(":id", $id);
$s->execute();
$r = $s->fetch();

New behaviour:

$q = $this->qb->select()->setTable("someTable")->where()->equals("id", "myID")->end();
$s = $this->qb->write($q);
// $s looks like this: SELECT someTable.* from someTable WHERE id = :myID
$s = parent::prepare($s);
// Context: the surrounding class extends PDO
$s->bindValue(":myID", $id);
$s->execute();
$r = $s->fetch();

Note how the placeholder changed from the generic :v1 to a useable (even if the query was generated dymically) :myID - if (for whatever reason) myID was used twice, the placeholder changes to :myID1 and so on.

nitricware commented 5 years ago

Maybe I use the software all wrong... well, I did.

The tutorial was not quite clear about the ->getValues() thing in the WHERE-Section