我已经阅读了使用 WHERE 子句将数组传递给查询,这基本上是我正在做的,但使用字符串而不是整数。我对 WHERE 子句有疑问。
$codes_imp = "'" . implode("','", $codes) . "'";
$passwords_imp = "'" . implode("','", $passwords) . "'";
$comments_imp = "'" . implode("','", $comments) . "'";
$set_pass_query = "INSERT INTO users (password, comments) VALUES ($passwords_imp, $comments_imp) WHERE Code IN ($codes_imp)";
执行时,查询如下所示:
INSERT INTO users (password, comments)
VALUES ('password1', 'password2', 'password3', 'comment1', 'comment2', 'comment3')
WHERE Code IN ('code1', 'code2', 'code3')
表中的所有列都是类型VARCHAR
。显然我有一个语法错误(正如它告诉我的那样),但我不确定如何正确构建它。