【发布时间】:2012-01-24 20:41:32
【问题描述】:
我尝试将以下 MySQL 查询转换为等效的 Zend select() 语句:
SELECT `entity_id` FROM `my_table` WHERE `attribute_id` IN (541,554,555,556) \
AND LOWER(REPLACE(TRIM(`value`), '-', '')) REGEXP '([^[:space:]]* )?$param$'
$param 是一个 PHP 变量,经过过滤后仅包含字母数字字符。
这是到目前为止我使用 Zend select() 语句所做的:
$db->select()
->from('my_table', 'entity_id')
->where('attribute_id IN (?)', array(541,554,555,556))
->where('LOWER(REPLACE(TRIM('
. $db->quoteIdentifier('value')
. '), "-", "")) REGEXP "([^[:space:]]* )?'
. $param
. '$"');
实际输出的 SQL,当$param = 'foo':
SELECT `entity_id` FROM `my_table` WHERE (attribute_id IN (541, 554, 555, 556)) \
AND (LOWER(REPLACE(TRIM(`value`), "-", "")) REGEXP "([^[:space:]]* )foo$")
我需要能够告诉 where() 不要尝试替换问号。怎么样?
【问题讨论】:
-
我意识到我可以使用等效的
REGEXP "([^[:space:]]* ){0,1}foo$。我仍然想知道是否可以使用“?”在select()声明中而不被替换。 -
问题是如何转义
?字符,使其不会被视为占位符,对吧?
标签: php mysql zend-framework