【发布时间】:2019-12-18 22:58:28
【问题描述】:
$search_query = mysqli_real_escape_string($conn, $_POST['this']);
$sql = "SELECT this FROM that WHERE this LIKE ' '%' + " .$search_query. " + '%' '";
这是我目前所拥有的,这个语法有问题吗?
【问题讨论】:
-
您在
LIKE和您的语句末尾放错了单引号。应该是:$sql = "SELECT this FROM that WHERE this LIKE '%' + '" .$search_query. "' + '%' ". -
@GMB 那时我可能做得不对,因为我无法回显结果。如果我这样做 $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); echo mb_substr($row["this"]);
-
呼应@GMB 拜托拜托使用准备好的陈述!像你这样编写 SQL 命令非常不安全。
-
MySQL 不使用
+进行字符串连接,它使用CONCAT()函数。