我试图在搜索工具中处理空格 - 专门用于处理名字和姓氏,我可以让我的查询在命令行上工作,但是当我尝试将它们转换为modx /时pdo语法我没有得到结果。 [因为标准没有正确翻译]
我拥有的是:
$criteria->where(array(
'Entities.first_name:LIKE' => "%$searchQuery%",
'OR:Entities.cams:LIKE' => "%$searchQuery%",
'OR:Entities.last_name:LIKE' => "%$searchQuery%",
'OR:Entities.company:LIKE' => "%$searchQuery%",
'OR:CONCAT(`Entites`.`first_name`," ",`Entities`.`last_name`):LIKE' => "%$searchQuery%",
));
问题在于最后的OR:CONCAT行,如果我转储查询我的where子句如下:
WHERE (
`Entities`.`first_name` LIKE '%first last%'
OR `Entities`.`cams` LIKE '%first last%'
OR `Entities`.`last_name` LIKE '%first last%'
OR `Entities`.`company` LIKE '%first last%'
OR `CONCAT(`Entites`.`first_name`," ",`Entities` LIKE '%first last%'
)
它在CONCAT之前添加了一个反引号并省略了。last_name
)
正确的语法是什么?
答案 0 :(得分:0)
高级条件通常需要构造为字符串而不是键=>价值配对。
以下对原始查询并不完全正确,但应该给出相同的结果:
$c->where(array(
'Entities.first_name:LIKE' => "%$searchQuery%",
'OR:Entities.cams:LIKE' => "%$searchQuery%",
'OR:Entities.last_name:LIKE' => "%$searchQuery%",
'OR:Entities.company:LIKE' => "%$searchQuery%",
));
$c->orCondition("CONCAT(Entities.first_name,' ',Entities.last_name) LIKE '%$searchQuery%'");
或者将整组OR条件作为字符串传递,以完全重现您的查询:
$c->where("
Entities.first_name LIKE '%$searchQuery%'
OR Entities.cams LIKE '%$searchQuery%'
OR Entities.last_name LIKE '%$searchQuery%'
OR Entities.company LIKE '%$searchQuery%'
OR CONCAT(Entities.first_name,' ',Entities.last_name) LIKE '%$searchQuery%'
");