Multiple parameters in Zend_Db::quoteInto()

Zend_Db has a nice function called quoteInto(). As it is described in the documentation - "The method simply interpolates the value into the string, escapes special characters, and applies quotes around it.".

Let's say you have an sql query which looks like this:

  1. SELECT * FROM users WHERE enabled = ? AND country = ?

You wouldn't be able to use the native quoteInto function to replace both question marks in the sql without processing the same string twice:

  1. $users = new Users();
  2. $sql = 'SELECT * FROM users WHERE enabled = ? AND country = ?';
  3. $sql = $users->getAdapter()->quoteInto($sql, 1);
  4. $sql = $users->getAdapter()->quoteInto($sql, 'UK');

This would get you

  1. SELECT * FROM users WHERE enabled = 1 AND country = 'UK'

Unfortunately this is not the best way to do it. Imagine what the code would look like if you needed to replace 3, 5 or even more placeholders.

This is where our custom extension to Zend_Db_Table_Abstract comes in handy.

Showing 1 - 1 of 1 results