本文介紹了致命錯誤:調用未定義的方法 mysqli::error()的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我可以連接,但是當涉及到準備好的語句時,我遇到了錯誤.有什么問題嗎?
I can connect but when it comes to the prepared statement that is the error i got. anything wrong there?
代碼:
// Open connection
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
//check connection
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", 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());
推薦答案
對于那些偶然發現此頁面的人.
For those who stumbled on this page.
你從中得到的錯誤
Fatal error: Call to undefined method mysqli::error()
這是因為我們需要將錯誤作為變量而不是作為函數
This is because we need to access the error as variable not as function
所以正確的代碼是
if(! empty( $mysqli->error ) ){
echo $mysqli->error; // <- this is not a function call error()
}
這篇關于致命錯誤:調用未定義的方法 mysqli::error()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!