Php Zend3我喜欢Postgresql中的搜索

Php Zend3我喜欢Postgresql中的搜索,php,postgresql,zend-framework,Php,Postgresql,Zend Framework,我的表中有数据,数据库Postgresql,它是小写和大写的,例如“Apple”。 我有一个搜索输入文本字段。如何将数据库中的数据转换为小写,以便在文本字段中键入“Apple”时返回“Apple” $select->where->like(Fruit::fruit_name, "%" . strtoupper($fruitName) . "%"); 您应该使用来执行此操作,或者只使用where而不使用like If you provide a string, this string

我的表中有数据,数据库Postgresql,它是小写和大写的,例如“Apple”。 我有一个搜索输入文本字段。如何将数据库中的数据转换为小写,以便在文本字段中键入“Apple”时返回“Apple”

$select->where->like(Fruit::fruit_name, "%" . strtoupper($fruitName) . "%");
您应该使用来执行此操作,或者只使用
where
而不使用like

If you provide a string, this string will be used to create a Zend\Db\Sql\Predicate\Expression instance, and its contents will be applied as-is, with no quoting:
您是否尝试过以下方法:

$select->where(sprintf('%s iLIKE %%%s%%', Fruit::fruit_name, strtoupper($fruitName));
我们已经找到了解决方案:

use Zend\Db\Sql\Expression;
$upperExpr = new Expression('LOWER(?)', [Fruit::fruit_name], [Expression::TYPE_IDENTIFIER]);
$select->where->like($upperExpr, "%" . mb_strtolower($fruitName, 'UTF-8') . "%");
或者只有strtolower()如果您没有“äÄöÖÜ”;)

这将创建正确的SQL语句