以下语法是我现有的语法.
$dbh = connect();
$singer = strtolower($_GET["singer"]);
$SQL =
"SELECT *
FROM table
WHERE field1 LIKE ?
ORDER BY field2 ASC";
$sth = $dbh-> prepare ($SQL);
$sth->bindParam (1, $singer);
$sth->execute();
Run Code Online (Sandbox Code Playgroud)
我需要对WHERE field1 LIKE ?使用通配符执行查询的代码行进行哪些更改%?
我试过WHERE field1 LIKE '%?%'但是没用.
我必须先做 '%
并附加 %'
到存储的值$singer?
尝试
$str = "%".$singer."%";
$SQL =
"SELECT *
FROM table
WHERE field1 LIKE ?
ORDER BY field2 ASC";
$sth = $dbh-> prepare ($SQL);
$sth->bindParam (1, $str);
Run Code Online (Sandbox Code Playgroud)
参考 ==>参见第3个例子