2016-11-14 66 views
-3

我已經將PHP版本從5切換到7,並且在連接到數據庫期間發生以下錯誤。PHP消息:PHP注意:未定義變量:conn

FastCGI的在標準錯誤發送:「PHP消息:通知PHP:未定義變量:CONN在/www/admin/Connection.php線14上

  1. 從命令行到數據庫的連接是OK 。
  2. 連接,從標準的PHP代碼數據庫確定爲好。

    <?php 
    class Connection 
    { 
    private static $conn; 
    private $dbHost; 
    private $dbUser; 
    private $dbPass; 
    private $dbName; 
    public $dbHandle; 
    public $languages; 
    
    public static function getConnection() 
    { 
         if($conn == null) 
           self::$conn = new Connection(); 
         return self::$conn; 
    } 
    
    protected function __construct() 
    { 
         $this->dbhost = BV_DB_HOST; 
         $this->dbuser = BV_DB_USER; 
         $this->dbpass = BV_DB_PASS; 
         $this->dbname = BV_DB_NAME; 
         $this->dbConnect(); 
    } 
    
    public function dbConnect() 
    { 
         $this->dbHandle = mysqli_connect(BV_DB_HOST, BV_DB_USER, BV_DB_PASS); 
         $tmp = mysqli_select_db($this->dbHandle, BV_DB_NAME); 
         mysqli_query($this->dbHandle, "set names utf8"); 
         return $tmp; 
    } 
    
    public function languages() 
    { 
         return explode(";", BV_LANGS); 
    } 
    } 
    ?> 
    

我該如何解決該問題?

回答

0

我在getConnection()中的IF語句中更改了條件,如下所示。

if(!isset($conn))