繁体   English   中英

PHP MySQL预准备语句:Execute死,不返回true或false

[英]PHP MySQL prepared statement: Execute dies, returns neither true or false

在此块中,$ stmt不返回预期的false,$ bind为true,但是当我进入$ stmt-> execute()时,它退出,并且不返回true或false。 我唯一能弄明白的是,如果我根据文档中的说明在参数中使用一些变量进行执行,但是我从未在execute调用中使用参数,也找不到其他人的示例在程序准备语句中使用一个。 我不知道我是否想念什么。 有人有想法么?

$stmt = $mysqli->prepare("SELECT ... FROM `table` WHERE `tid` = ?");

if ($stmt !== FALSE) {
    echo 'Statement was true.';
    $bind = $stmt->bind_param('s', $this->tid);
    echo 'after bind';
    if ($bind)
        echo 'bind was good ';
    else
        echo 'bind was bad';
    $exec = $stmt->execute();
    if ($exec)
        echo 'exec was good';
    else
        echo 'exec was bad';
    echo 'after execute';
    // etc.
} else {
 // rest of code
}

@tntu接受的答案和以下评论使我走上了解决这个问题的正确道路。 [link] http://stackoverflow.com/questions/5580039/fatal-error-uncaught-exception-mysqli-sql-exception-with-message-no-index-us

MySQL可以做很多错误报告,并且我已经在堆栈和相关函数中设置了mysqli_report(MYSQLI_REPORT_ALL),以便找出其他问题。 无论如何,设置mysqli_report(MYSQLI_REPORT_OFF)可使执行按预期运行,而不会使php出现警告和错误。

$bind = $stmt->bind_param('s', $this->tid);

s代表字符串

将其更改为i ,它应该可以工作。

另请参阅有关执行一些错误管理的内容。 mysqli_erromysqli_errno

像这样:

if ($mysqli->errno) { logging("ERRO: ".$mysqli->error . "( " . $mysqli->errno . " )"); }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM