diff --git a/library/Zend/Db/Adapter/Abstract.php b/library/Zend/Db/Adapter/Abstract.php index 07f9c5a2bd..fac961859d 100644 --- a/library/Zend/Db/Adapter/Abstract.php +++ b/library/Zend/Db/Adapter/Abstract.php @@ -930,13 +930,7 @@ public function quoteInto($text, $value, $type = null, $count = null) if ($count === null) { return str_replace('?', $this->quote($value, $type), $text); } else { - while ($count > 0) { - if (strpos($text, '?') !== false) { - $text = substr_replace($text, $this->quote($value, $type), strpos($text, '?'), 1); - } - --$count; - } - return $text; + return implode($this->quote($value, $type), explode('?', $text, $count + 1)); } } diff --git a/tests/Zend/Db/Adapter/TestCommon.php b/tests/Zend/Db/Adapter/TestCommon.php index 8f7cfba3c8..c2d8edf638 100644 --- a/tests/Zend/Db/Adapter/TestCommon.php +++ b/tests/Zend/Db/Adapter/TestCommon.php @@ -1267,6 +1267,16 @@ public function testAdapterQuoteIntoCount() 'Incorrect quoteInto() result for count'); } + public function testAdapterQuoteIntoCountAndQuestionMark() + { + $string = 'foo = ? OR moo = ? OR boo = ?'; + $param = 'What?'; + $value = $this->_db->quoteInto($string, $param, null, 2); + $this->assertTrue(is_string($value)); + $this->assertEquals("foo = 'What?' OR moo = 'What?' OR boo = ?", $value, + 'Incorrect quoteInto() result for count and question mark in value'); + } + public function testAdapterQuoteTypeInt() { foreach ($this->_numericDataTypes as $typeName => $type) {