简体   繁体   中英

Using LIKE CONCAT with wildcard

I'm using the standard LAMP environment. I've taken an example directly from mysql.com website and adapted it to my table structure.

$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 ("%").

Use double quotes as string delimiters for your sql string.

$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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