1

已解决 - 愚蠢的我....感谢评论者的指点,$mysqli->error 显示我没有向 mysql 用户授予 DELETE 权限。添加后一切都很好。


我似乎无法让这个查询继续下去。成功连接到数据库,但无法删除“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();

?>

我真的在这里摸不着头脑,任何帮助将不胜感激!

4

0 回答 0