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

Source: Internet
Author: User
$info=M("qq")->where('name like','$name%')->select();

Is there a wrong writing in the Where? The following error message is given: 1064:you has an error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-to-use (") ' at line 1 [SQL statement]: SELECT * from qq WHERE (name)

If you follow the example of Baidu like username ' admin% '
$info =m ("QQ")->where (name like ' $name% ')->select ();
will also error: syntax error, unexpected ' like ' (t_string)

Reply content:

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

Is there a wrong writing in the Where? The following error message is given: 1064:you has an error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-to-use (") ' at line 1 [SQL statement]: SELECT * from qq WHERE (name)

If you follow the example of Baidu like username ' admin% '
$info =m ("QQ")->where (name like ' $name% ')->select ();
will also error: syntax error, unexpected ' like ' (t_string)

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

There is time to look at the source of the Where method or look at the PDO parameter bindings will help a lot

//试试用这段代码:M('qq')->where(['name'=>['LIKE',"$name%"])->select();

See TP Document: http://www.kancloud.cn/manual/thinkphp/1768

Buxie.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.