2012-08-14 64 views
2

我可以連接,但是當涉及到準備語句,這是我得到的錯誤。有什麼不對?致命的錯誤:調用未定義的方法mysqli :: error()

代碼:

// 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()); 

回答

0

我不好,不應該有在列字段的SQL語句的報價。現在它工作了!

6

對於那些偶然發現在這個頁面上的人。

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

此得到的錯誤是因爲我們需要訪問誤差變量沒有功能

所以正確的代碼是

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

希望這可以幫助某人。

相關問題