Mysqli::query(): 資料庫連線錯誤
「mysqli::query(): 無法取得mysqli」錯誤通常表示資料庫連線有問題。以下步驟描述了該問題並根據提供的程式碼片段提供了解決方案:
解:
修改後的程式碼:
// Connection file $DBConnect = new mysqli("localhost", "root@localhost", NULL, "Ladle"); // Check for connection error if ($DBConnect->connect_errno) { $ErrorMsgs[] = "The database server is not available. Connect Error is " . $DBConnect->connect_errno . " " . $DBConnect->connect_error . "."; } // Class class EventCalendar { private $DBConnect = NULL; function __construct() { include("inc_LadleDB.php"); $this->DBConnect = $DBConnect; } function __destruct() { // Close the connection only if it's not closed already if (!$this->DBConnect->connect_error) { $this->DBConnect->close(); } } function __wakeup() { // Include the database connection data include("inc_LadleDB.php"); $this->DBConnect = $DBConnect; } // Event adding method // ... }
以上是為什麼我的 mysqli::query() 失敗並出現'無法獲取 mysqli”資料庫連接錯誤?的詳細內容。更多資訊請關注PHP中文網其他相關文章!