Home >Backend Development >PHP Tutorial >What's wrong with this sentence of the TP framework?

What's wrong with this sentence of the TP framework?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-06 13:53:281243browse

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

Is it written incorrectly in where? Give the following error message: 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 statement]: SELECT * FROM qq WHERE ( name like )

If you write the like example username like 'Admin%' from Baidu like this
$info=M("qq")->where(name like '$name%')->select( );
will also report an error: syntax error, unexpected 'like' (T_STRING)

Reply content:

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

Is it written incorrectly in where? Give the following error message: 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 statement]: SELECT * FROM qq WHERE ( name like )

If you write the like example username like 'Admin%' from Baidu like this
$info=M("qq")->where(name like '$name%')->select( );
will also report an error: syntax error, unexpected 'like' (T_STRING)

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

If you have time, you can look at the source code of the where method or look at the pdo parameter binding, it will be of great help

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

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

See tp documentation: http://www.kancloud.cn/manual/thinkphp/1768

You’re welcome.

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