2017-05-25 16 views
0

對不起,我對PHP沒有太多的瞭解,我需要一點幫助將一個網站從一臺服務器遷移到另一臺服務器,服務器有操作系統和PHP 舊版本的移動過的文件到新的服務器和數據庫我運行的網站,並獲得網站遷移後,我得到一個MySQL錯誤不推薦:mysql_pconnect():

棄用後:mysql_pconnect():mysql擴展已被棄用, 將被刪除在未來:使用mysqli或PDO代替 /var/www/classes/dbcon.class.php 45行

這裏是從那個文件的代碼我已經嘗試改變幾行並嘗試使用MySqli來代替,但我似乎無法得到它的工作。

<?php 



class dbCon 
{ 
    // 
    // private variables 
    // 

    var $_hostname_Con; 
    var $_database_Con; 
    var $_username_Con; 
    var $_password_Con; 
    var $_Con; 

    var $_result; 
    var $_hasData; 
    var $_lastQuery; 
    var $_row; 
    var $_rowCount; 

    // 
    // methods (private) 
    // 

    // 
    // methods (public) 
    // 

    // constructor 
    function dbCon() 

    { 
     $this->_hostname_Con = "localhost"; 
     $this->_database_Con = "street"; 
     $this->_username_Con = "rt"; 
     $this->_password_Con = "mwL"; 
     //* 
     $this->_database_Con = "cranes_cms"; 
     $this->_username_Con = "t"; 
     $this->_password_Con = "mob"; 
     //*/ 

     $this->_Con = mysql_pconnect ($this->_hostname_Con, $this->_username_Con, $this->_password_Con) or trigger_error(mysql_error(),E_USER_ERROR); 
     mysql_select_db($this->_database_Con) or die('Could not select database'); 
    } 

    function freeResult() 
    { 
     mysql_free_result($this->_result);  
    } 

    function close() 
    { 
     mysql_close($this->_Con); 
    } 


    function update($inQuery) 
    { 
     //reset row counter and data flag 
     $this->_rowCount = 0; 
     $this->_hasData = FALSE; 

     //do SQL 
     $this->_lastQuery = $inQuery; 
     mysql_query($this->_lastQuery,$this->_Con) or die('Query failed: ' . mysql_error()); 
    } 

    function select($inQuery) 
    { 
     //reset row counter and data flag 
     $this->_rowCount = 0; 
     $this->_hasData = FALSE; 

     //do SQL 
     $this->_lastQuery = $inQuery; 
     $this->_result = mysql_query($this->_lastQuery,$this->_Con) or die('Query failed: ' . mysql_error()); 

     //set has data flag 
     if (mysql_num_rows($this->_result)) 
      {$this->_rowCount = mysql_num_rows($this->_result);} 
     else 
      {$this->_rowCount = 0; } 

     if ($this->_rowCount > 0) 
      {$this->_hasData = TRUE;} 
     else 
      {$this->_hasData = FALSE;} 

    } 

    function getData() 
    { 
    if ($this->_hasData) 
     { 
      if ($this->_row = mysql_fetch_array($this->_result, MYSQL_ASSOC)) 
       { 
        return $this->_row; 
       } 
      else 
       { 
        return FALSE; 
       } 
     } 
    else 
     { 
     return FALSE; 
     } 
    } 

    function getRowCount() 
    { 
     return $this->_rowCount; 
    } 

    function hasData() 
    { 
     return $this->_hasData; 
    } 
// end 
} 

?> 

這是別人的代碼,我不確定在哪裏解決這個問題。任何人都可以請

+1

的可能的複製[推薦使用:MySQL的\ _pconnect():](https://stackoverflow.com/q/22834458/6521116) –

+0

的MySQL _ *()是deprecated.so使用mysqli的_ *() –

+0

如我說我對PHP沒有太多的瞭解,並且嘗試用mysqli替換mysql_pconnect行,但它似乎並不簡單 – MikeAsp

回答

0

這是一個使用mysqli _ *()的例子,你可以瞭解更多here

$mysqli = new mysqli("localhost", "my_user", "my_password", "world"); 

/* check connection */ 
if ($mysqli->connect_errno) { 
    printf("Connect failed: %s\n", $mysqli->connect_error); 
    exit(); 
} 

/* Create table doesn't return a resultset */ 
if ($mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) { 
    printf("Table myCity successfully created.\n"); 
} 

/* Select queries return a resultset */ 
if ($result = $mysqli->query("SELECT Name FROM City LIMIT 10")) { 
    printf("Select returned %d rows.\n", $result->num_rows); 

    /* free result set */ 
    $result->close(); 
}