【发布时间】:2018-02-12 14:56:26
【问题描述】:
我在本地主机上运行时收到错误消息。跟随我得到的味精。我还添加了数据库连接代码。
( ! ) 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
# Time Memory Function Location
1 0.0470 142760 {main}( ) ..\index.php:0
2 0.4050 634848 require_once( 'C:\wamp\www\common\conf\database.conf.php' ) ..\index.php:16
3 0.4060 635416 mysql_connect ( ) ..\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());
}
?>
【问题讨论】:
-
mysql PHP 扩展已死 -- 停止使用 mysql PHP 扩展。它是旧的,自 PHP 5.5 起已弃用,并在 PHP 7.0 中完全删除。请改用 mysqli 或 PDO_mysql。并且不要混合它们
-
Mysql_* 函数已弃用。此外,它们是不安全的Deprecated features in PHP 5.5.x。您应该使用 mysqli_ 函数或更好的 PDO 与准备好的语句。