已解决 - 愚蠢我....感谢评论者的指示,$ mysqli->错误显示我没有向mysql用户授予DELETE权限。添加之后一切都很好。
我似乎无法得到这个查询。连接成功对DB进行了连接,但是在“custom_messages”表中删除行时未能在日志中显示错误...方法1:
<?php
// get form.html input
$var1 = $_POST["var1"];
$var2 = $_POST["var2"];
$mysqli = new mysqli($_SERVER['DB_HOST'], $_SERVER['DB_USER'], $_SERVER['DB_PASS'],"theDB");
if ($mysqli->connect_errno) {
printf ( "Connect failed: %s\n", $mysqli->connect_error );
exit ();
} else {
printf ( "DB Connection Established.\n" );
if ($mysqli->query (sprintf ( "DELETE FROM custom_messages WHERE var1='%s' && var2='%s'", mysql_real_escape_string ( $var1, $var2 ) ) )) {
printf ( "%d rows deleted.\n", $mysqli->affected_rows );
}
//close DB connection
$mysqli->close();
?>
我也尝试了方法2,结果相同,没有删除任何行。它甚至可以回应'一个'..
<?php
// get form.html input
$var1 = $_POST["var1"];
$var2 = $_POST["var2"];
$mysqli = new mysqli($_SERVER['DB_HOST'], $_SERVER['DB_USER'], $_SERVER['DB_PASS'],"CCv2");
if ($mysqli->connect_errno) {
printf ( "Connect failed: %s\n", $mysqli->connect_error );
exit ();
} else {
printf ( "DB Connected.\n" );
$stmt = $mysqli->prepare("DELETE FROM custom_messages WHERE var1=? AND var2=?");
echo "one\n";
$stmt->bind_param('ss',$var1, $var2);
echo "two\n";
$stmt->execute();
$stmt->close();
printf ( "%d rows deleted.\n", $mysqli->affected_rows );
//close DB connection
$mysqli->close();
?>
我真的在这里摸不着头脑,任何帮助都会受到极大的赞赏!