2017-09-04 71 views
-2

在本地主機上運行時,收到錯誤消息。以下味精我越來越。我也添加了數據庫連接代碼。在本地主機上運行時獲取錯誤消息

(!) Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\common\conf\database.conf.php on line 51 
 
Call Stack 
 
# \t Time \t Memory \t Function \t Location 
 
1 \t 0.0470 \t 142760 \t {main}() \t ..\index.php:0 
 
2 \t 0.4050 \t 634848 \t require_once('C:\wamp\www\common\conf\database.conf.php') \t ..\index.php:16 
 
3 \t 0.4060 \t 635416 \t mysql_connect () \t ..\database.conf.php:51 
 

 

 
Database connection code 
 

 
<?php 
 
    /******************************************************* 
 
    * File name: database.conf.php 
 
    * 
 
    * Purpose: this file is used to store database 
 
    *   table name constants and it also starts 
 
    *   the database connection 
 
    * 
 
    * CVS ID: $Id$ 
 
    * 
 
    ********************************************************/ 
 

 
    // If main configuration file which defines VERSION constant 
 
    // is not loaded, die! 
 
    if (! defined('VERSION')) 
 
    { 
 
     echo "You cannot access this file directly!"; 
 
     die(); 
 
    } 
 

 
    // Please note: 
 
    // in production mode, the database authentication information 
 
    // may vary. 
 
    
 
    
 
    define('DB_USER', 'root'); 
 
    define('DB_PASS', ''); 
 
    //   
 
    define('DB_NAME', 'myrentbd-db'); 
 
    define('DB_HOST', 'localhost'); 
 
    
 
    /** 
 
    * Common Table Constant 
 
    */ 
 
    // Common Tables 
 
    define('APP_INFO_TBL',     DB_NAME . '.app_info'); 
 
    define('APP_LANGUAGE_TBL',    DB_NAME . '.app_language'); 
 
    define('APP_MESSAGE_TBL',    DB_NAME . '.app_message'); 
 
    define('APP_META_TBL',     DB_NAME . '.app_meta'); 
 
    define('APP_PROFILE_TBL',    DB_NAME . '.app_profile'); 
 

 
    define('COUNTRY_LOOKUP_TBL',   DB_NAME . '.country_lookup'); 
 
    define('US_STATE_TBL',     DB_NAME . '.us_states'); 
 

 
    define('DOCUMENT_TBL',     DB_NAME . '.document'); 
 

 
    define('GROUP_TBL',     DB_NAME . '.group'); 
 
    
 
    if (AUTO_CONNECT_TO_DATABASE) 
 
    { 
 
     $dbcon = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Could not connect: " . mysql_error()); 
 
     mysql_select_db(DB_NAME, $dbcon) or die("Could not find: " . mysql_error()); 
 
    } 
 

 
?>

+3

MySQL的PHP​​擴展已經死了 - 停止使用mysql的PHP擴展。這是舊的,從PHP 5.5開始不推薦使用,並且在PHP 7.0中完全刪除。改用mysqli或PDO_mysql。並且不要混合使用 –

+0

不建議使用Mysql_ *函數。此外,它們是不安全的[PHP 5.5.x中的棄用功能](http://php.net/manual/de/migration55.deprecated.php)。您應該使用mysqli_函數或更好的PDO和預準備語句。 – BenRoob

回答

1

使用mysqli的函數mysql_connect()函數

在PHP 5.5顯示警告消息:MySQL擴展已被棄用

在已完全除去PHP 7

+0

對不起,我不是編寫代碼的專家。你能提出建議,特別是我必須改變的地方嗎? –

+0

你必須改變mysql_connect(DB_HOST,DB_USER,DB_PASS)到mysqli_connect(「localhost」,「my_user」,「my_password」,「my_db」)等數據庫連接和其他CRUD操作 –

相關問題