43

警告: mysqli::query(): C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\my Portable files\class_EventCalendar.php の行 43 で mysqli を取得できませんでした

以下は私の接続ファイルです:

<?php
if(!isset($_SESSION)) 
{ 
    session_start(); 
}  

// Create array to hold error messages (if any)
$ErrorMsgs = array();

// Create new mysql connection object
$DBConnect = @new mysqli("localhost","root@localhost", 
            NULL,"Ladle");

// Check to see if connection errno data member is not 0 (indicating an error)
if ($DBConnect->connect_errno) {

    // Add error to errors array
    $ErrorMsgs[]="The database server is not available.".
               " Connect Error is ".$DBConnect->connect_errno." ".
               $DBConnect->connect_error.".";
}
?>

これは私のクラスです:

 <?php 
    class EventCalendar {
        private $DBConnect = NULL;

        function __construct() {
            // Include the database connection data
            include("inc_LadleDB.php");
            $this->DBConnect = $DBConnect;  
        }

        function __destruct() {
            if (!$this->DBConnect->connect_error) {
                $this->DBConnect->close();
            }
        }

        function __wakeup() {
            // Include the database connection data
            include("inc_LadleDB.php");     
            $this->DBConnect = $DBConnect;
        }


        // Function to add events to Zodiac calendar
        public function addEvent($Date, $Title, $Description) {
            // Check to see if the required fields of Date and Title have been entered
            if ((!empty($Date)) && (!empty($Title))) {
                /* if all fields are complete then they are 
                   inserted into the Zodiac event_calendar table */
                $SQLString = "INSERT INTO tblSignUps".
                           " (EventDate, Title, Description) ".
                           " VALUES('$Date', '$Title', '".
                            $Description."')";

                // Store query results in a variable
                $QueryResult = $this->DBConnect->query($SQLString);

私は OOP PHP が苦手で、このエラーが発生する理由がわかりません。このコードを別の場所から取得しましたが、変更したのは@new mysqliパラメーターだけでした。何が問題なのかを理解するのを手伝ってくれる人はいますか?

4

4 に答える 4

105

おそらくどこかDBconnection->close();で、いくつかのクエリを実行しようとします。


ヒント...->close();: 挿入するのが間違っている場合があります__destruct()(__destructイベントの後で、クエリの実行が必要になるため)。

于 2014-10-01T17:48:30.563 に答える
5

私も同じ問題を抱えていました。「localhost」と書く代わりに、mysqli オブジェクトの localhost パラメータを「127.0.0.1」に変更しました。出来た; 方法や理由はわかりません。

$db_connection = new mysqli("127.0.0.1","root","","db_name");
于 2018-04-29T07:49:38.163 に答える