Home  >  Article  >  Backend Development  >  TP框架的这句话哪里不对?

TP框架的这句话哪里不对?

WBOY
WBOYOriginal
2016-07-06 13:53:281161browse

<code>$info=M("qq")->where('name like','$name%')->select();</code>

where里面是不是写的不对?给如下的错误提示:1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 [ SQL语句 ] : SELECT * FROM qq WHERE ( name like )

如果按百度出来的like的例子username like 'Admin%' 这样写的话
$info=M("qq")->where(name like '$name%')->select();
也是会报错:syntax error, unexpected 'like' (T_STRING)

回复内容:

<code>$info=M("qq")->where('name like','$name%')->select();</code>

where里面是不是写的不对?给如下的错误提示:1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 [ SQL语句 ] : SELECT * FROM qq WHERE ( name like )

如果按百度出来的like的例子username like 'Admin%' 这样写的话
$info=M("qq")->where(name like '$name%')->select();
也是会报错:syntax error, unexpected 'like' (T_STRING)

<code>$info=M("qq")->where("name like '%s'",array($name))->select();</code>

有时间可以看下 where方法的源码 或 看下pdo参数绑定 会有很大帮助

<code>//试试用这段代码:

M('qq')->where(['name'=>['LIKE',"$name%"])->select();</code>

见tp文档:http://www.kancloud.cn/manual/thinkphp/1768

不谢。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn