Postgresql ZF2-如何正确连接包含CONCAT函数的select语句

Postgresql ZF2-如何正确连接包含CONCAT函数的select语句,postgresql,zend-framework,Postgresql,Zend Framework,我是Zend和Postgres的新手。我的Users表包含FirstName列和LastName列 我想使用单个“全名”字符串查询表;e、 g.$search='John Sm' 我试图使用CONCAT_WS函数连接表中的两个名称,然后将其与搜索字符串进行比较 我的声明 $select->where(数组('CONCAT_WS(“,'u.”“FirstName”,“u.”“LastName”)像?'=>数组(“%$search%”)); 我尝试过不同的组合,但似乎无法正确连接 我想要的语句的一

我是Zend和Postgres的新手。我的
Users
表包含
FirstName
列和
LastName

我想使用单个“全名”字符串查询表;e、 g.
$search='John Sm'

我试图使用
CONCAT_WS
函数连接表中的两个名称,然后将其与搜索字符串进行比较

我的声明

$select->where(数组('CONCAT_WS(“,'u.”“FirstName”,“u.”“LastName”)像?'=>数组(“%$search%”));

我尝试过不同的组合,但似乎无法正确连接


我想要的语句的一个例子是从“firstname lastname”如“%john s%”的用户中选择*

这并不能回答您的问题,但您是否考虑对此进行查看?

您是否查看了文档的最新版本


如果在
$select->where()
中使用数组作为参数,它将被解释为成对的
['column1'=>'value','column2'=>'value']
。在此解决方案中,您不能使用函数和查询的组合部分

您可以使用
Zend\Db\Sql\Predicate\Literal()
,例如:

$select->where
  ->literal('CONCAT_WS(" ", "u"."FirstName", "u"."LastName") LIKE \'%word%\'')
$select->where
      ->expression('CONCAT_WS(" ", "u"."FirstName", "u"."LastName") LIKE \'%?%\'', $word)
或者使用
Zend\Db\Sql\Predicate\Expression()
,例如:

$select->where
  ->literal('CONCAT_WS(" ", "u"."FirstName", "u"."LastName") LIKE \'%word%\'')
$select->where
      ->expression('CONCAT_WS(" ", "u"."FirstName", "u"."LastName") LIKE \'%?%\'', $word)
(如果变量更多,则第二个参数可以是bee数组)

在此解决方案中,您可以使用相同的方法构建sql
WHERE

$select->where
  ->equalsTo()
  ->or
  ->greatherThan()
  ->and
  ->like()
  ->nest()
    ->lessThan()
    ->or
    ->literal()
  ->unnest()
  ...

您还可以构建为
Zend\Db\Sql\Where
/
Zend\Db\Sql\Predicate
,例如:

$where = new Where();
$where->equalsTo();// and more, more, more, with sub-where inclusive
$select->where->predicate($where);