致命错误:调用未定义的方法的mysqli ::错误()[复制](Fatal error: Call

2019-06-27 01:13发布

这个问题已经在这里有一个答案:

  • 当使用单引号,双引号,反引号和MySQL中的 12个回答

我可以连接,但是当涉及到准备好的语句是我得到的错误。 什么不对劲的地方?

码:

    // Open connection
    $db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

    //check connection
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }

    // Create statement object
    $stmt = $db->stmt_init();   

    // sql statement
    $sql = "INSERT INTO ch_users ('uid','admin','password','directory','size','format','locationid') VALUES (?, 1, ?, ?, ?, ?, 1)";

    // Create a prepared statement
    $stmt = $db->prepare($sql) or die($db->error());

Answer 1:

对于那些谁在此页上跌跌撞撞。

你得到的错误

Fatal error: Call to undefined method mysqli::error()

这是因为我们需要不能访问错误的变量 函数

所以正确的代码

if(! empty( $mysqli->error ) ){
   echo $mysqli->error;  // <- this is not a function call error()
}

希望这可以帮助别人。



Answer 2:

我不好,不应该有在列字段的SQL语句的报价。 现在,它的作品!



文章来源: Fatal error: Call to undefined method mysqli::error() [duplicate]
标签: php mysqli