在本地主机上运行时获取错误消息
问题描述:
在本地主机上运行时,收到错误消息。以下味精我越来越。我也添加了数据库连接代码。在本地主机上运行时获取错误消息
(!) 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());
}
?>
答
使用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操作 –
MySQL的PHP扩展已经死了 - 停止使用mysql的PHP扩展。这是旧的,从PHP 5.5开始不推荐使用,并且在PHP 7.0中完全删除。改用mysqli或PDO_mysql。并且不要混合使用 –
不建议使用Mysql_ *函数。此外,它们是不安全的[PHP 5.5.x中的弃用功能](http://php.net/manual/de/migration55.deprecated.php)。您应该使用mysqli_函数或更好的PDO和预准备语句。 – BenRoob