简体   繁体   English

将LIKE CONCAT与通配符一起使用

[英]Using LIKE CONCAT with wildcard

I'm using the standard LAMP environment. 我正在使用标准的LAMP环境。 I've taken an example directly from mysql.com website and adapted it to my table structure. 我直接从mysql.com网站上获取了一个示例,并将其调整为我的表结构。

$sql = 'SELECT cat_name
FROM cats
WHERE cat_name LIKE concat('%', 'Artist', '%') ';
  • But this does not work... the screen is just blank and even "view source" in the browser is blank 但这不起作用...屏幕只是空白,甚至浏览器中的“查看源代码”都是空白

My issue is that, even though all of the examples I've found on StackOverflow and other forums use single quotes ('%') it only works if I use double quotes like this ("%"). 我的问题是,即使我在StackOverflow和其他论坛上找到的所有示例都使用单引号('%'),它也只能在我使用此类双引号(“%”)的情况下起作用。

Use double quotes as string delimiters for your sql string. 使用双引号作为sql字符串的字符串定界符。

$sql = "SELECT cat_name
        FROM cats
        WHERE cat_name LIKE concat('%', 'Artist', '%')";

If you use the same string delimiter for both (your sql string and strings in your sql string) then this will terminate your sql string before you want it. 如果您对两者(您的sql字符串和sql字符串中的字符串)使用相同的字符串定界符,则这将在您需要之前终止sql字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM