Mysql Like Syntax

时间:2009-08-18 17:17:10

标签: mysql sql-like

快速提问:mysqli_escape_string如何包含在like子句中的变量?

"SELECT * FROM table WHERE name LIKE '%". %s . "%'"    

"SELECT * FROM table WHERE name like '%"."%s"."%'"

不行。

谢谢!

1 个答案:

答案 0 :(得分:5)

$value = mysql_real_escape_string($_POST["terms"]);
$query = "SELECT * FROM table WHERE name LIKE '%".$value."%'";

或者你可以用这样的sprintf来实现这个:

$query = sprintf("SELECT * FROM table WHERE name LIKE '%s'", "%".$value."%");