各位大神们
php函数里想把变量替换到sql里头,$sql = "select * form t where name in ($names)"; $names 是个以逗号分隔的字符串,这样有问题吗
$names值为“张三,李四,王五”,真正mysql里in 里面的字符串是以单引号分隔的。
$names = '"张三','李四','王五'";
$sql = "select * form t where name in ($names)";
$ar = array("张三', '李四', '王五');
$names = join("'", $a);
$sql = "select * form t where name in ('$names')";
还可以
$sql = "select * form t where find_in_set(name, ''张三,'李四,'王五')";