php – zend db选择像通配符

我试图在zend db的选择中找到一些关于“like”子句的信息,但没有成功.
问题是如何在LIKE子句附近使用通配符“%”并不清楚

我最初使用过的坏主意是在网上的数百个地方推荐的

$db->select()
    ->where('text LIKE "%'.$query.'%"');

我想,正确答案是这样的:

$db->select()
    ->where('text LIKE ?',$query);

但是没有使用通配

我尝试了几种解决方案,但它们似乎都不起作用:

$db->select()
    ->where('text LIKE ?','%$query%');
$db->select()
    ->where('text LIKE ?','%{$query}%');

任何人都可以指向文档,或提供一个很好的解决方案吗?

The second argument to the where() method is optional. It is a value to substitute into the expression. Zend_Db_Select quotes the value and substitutes it for a question-mark (“?”) symbol in the expression.

说不够

解决方法

%符号需要是绑定到查询的变量的一部分.如果您使用双引号而不是单引号,那么您的第二个示例将起作用.所以你可以这样做:

$query = '%'.$query.'%';
$db->select()
   ->where('text LIKE ?',$query);

要么:

$db->select()
   ->where('text LIKE ?',"%$query%");

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...