Issues

ZF-651: Bind inconsistent in query() versus update()/delete().

Issue Type: Improvement Created: 2006-12-14T20:53:42.000+0000 Last Updated: 2008-12-19T13:13:49.000+0000 Status: Closed Fix version(s): - 0.9.3 (05/May/07)

Reporter: Alex Adriaanse (alexadriaanse) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db

Related issues: - ZF-1905

Attachments:

Description

Zend_Db_Adapter_Abstract::query(), Zend_Db_Select::where(), etc. allow you to bind variables to $sql/$where. However, in Zend_Db_Adapter_Abstract::update(), Zend_Db_Adapter_Abstract::delete(), Zend_Db_Table::update() and Zend_Db_Table::delete() it will not bind any variables to the $where variable.

Furthermore, Zend_Db_Table::fetchAll() and Zend_Db_Table::fetchOne() allow you to bind variables to $where, but you'd have to pass it as the values in the $where array rather than using a separate $bind variable, and you can only use question mark placeholders in those.

Unless this was done deliberately, it'd be nice if Zend_Db_Adapter_Abstract, Zend_Db_Select, and Zend_Db_Table would all use the same interface for binding variables. Essentially, always use a separate $bind variable to allow you to bind using either question mark placeholders or named placeholders.

It'd also be nice if one could directly pass arrays as one of the bind values (i.e. $bind would be an array of arrays) in all the aforementioned functions and it'd substitute a comma-separated list of values, just like how Zend_Db_Adapter_Abstract::quote() does it.

Again, if this is done by design then that's fine with me, so in that case just ignore this ticket. It's just that the different ways that variables need to be bound makes things a bit confusing.

Comments

Posted by Bill Karwin (bkarwin) on 2006-12-19T12:37:55.000+0000

Assigning to Bill Karwin. Scheduling for 0.8.

Posted by Bill Karwin (bkarwin) on 2006-12-19T12:38:47.000+0000

Assigning to Bill Karwin.

Posted by Darby Felton (darby) on 2007-04-20T17:37:22.000+0000

For Table::fetchAll(), we already have four optional parameters, and additional optional parameters would certainly take away from the simplicity of using the method.

For Table::update() and delete(), the $where parameter may be an array, and therefore, the usage of binding variables here would be difficult to document and to use, as the interface becomes more complex.

Posted by Piotr Kabacinski (kabot) on 2008-11-02T12:15:03.000+0000

bq. For Table::update() and delete(), the $where parameter may be an array, and therefore, the usage of binding variables here would be difficult to document and to use, as the interface becomes more complex.

But when you add third argument like Zend_Db_Table_Abstract::update(array $data, $where, $bind = array()) is it still possible to use method as it was before and in new way, for example:

<pre class="highlight">
class Table1 extends Zend_Db_Table_Abstract  {}

$t = new Table1();

$t->update(array('a', 'b'), array('id = ?'), 2); //for only one parameter it doesn't have to be array
$t->update(array('a', 'b'), array('id = ?', 'active = ?'), array(2, 1));

What do you think about this idea?

Posted by Wil Sinclair (wil) on 2008-12-19T13:13:49.000+0000

Bookkeeping. Closing old issues and assigning them to the person who ultimately resolved the issue.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts