php - 如何将 CONCAT_WS 与 IN 一起使用?

标签 php mysql symfony doctrine-orm

使用 Symfony2 和 Doctrine2,想把 CONCAT_WS 和 IN 结合起来,而不是写一大堆 IF。

WHERE CONCAT_WS('-', id2, id2) IN ($ids)

我收到这个错误:

[Syntax Error] line 0, col 446: Error: Expected Doctrine\\ORM\\Query\\Lexer::T_IN, got '('

$id 的形式为 '123-456'。

如果我只是使用一个列而不是 CONCAT_WS,它会起作用:

WHERE id2 IN ($ids)

最佳答案

并不是所有的 MySQL 函数都可以在 Doctrine 中使用。只有那些对所有受支持的数据库通用的函数可用。

点击此链接可查看默认可用的功能列表 http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#functions-operators-aggregates .

如果您仍然想使用 CONCAT_WS,请阅读以下链接中有关创建自定义函数的内容。您可以创建自己的 DQL 自定义函数,并且可以像以前一样使用。

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/dql-user-defined-functions.html

http://symfony.com/doc/current/cookbook/doctrine/custom_dql_functions.html

关于php - 如何将 CONCAT_WS 与 IN 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14945317/

相关文章:

mysql - 如何保存和保留日期毫秒(MySQL)

php - UNION ALL - 返回结果来自哪个表

php - 来自 2 个表的 MySql session

php - 将字符串替换为 MySQL 的结果

MySQL:如果在日期之后达到特定值,则获取所有行

php - 在 Doctrine 2 中使用类表继承时 : how can one write a Native SQL Query that will return results from a child class?

postgresql - 使用 doctrine2 postgresql 的模式更新总是 DROPs 然后 ADDs CONSTRAINTs

php - 尝试使用 symfony2 制作联系表单示例

php - 在 PHP 中获取请求的 "Content-Type" header

php - file_get_contents 显示图像不正确