Home >Backend Development >PHP Tutorial >The mysql extension is deprecated and will be removed in the future,这是什么原因啊该如何解决
The mysql extension is deprecated and will be removed in the future,这是什么原因啊?
我在我的电脑上配置了2-plan-team这个系统,这是用PHP写的,配置完后,打开index.php,却出现以下问题:PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in E:\server\2-plan-team\include\class.datenbank.php on line 38
class.datenbank.php的源代码:
/*
* The class datenbank (database) provides methods to handle a database connection
*
* @author original code from Open Dynamics.
* @name datenbank
* @version 0.4.6
* @package 2-plan
* @link http://2-plan.com
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License v3 or later
*/
class datenbank
{
/*
* Constructor
*/
function __construct()
{
}
/*
* Establish a database connection
*
* @param string $db Database name
* @param string $user Database user
* @param string $pass Password for database access
* @param string $host Database host
* @return bool
*/
function connect($db_name, $db_user, $db_pass, $db_host="localhost")
{
//mysql
//$db = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);
$conn = mysql_connect($db_host,$db_user,$db_pass);
$db_check = mysql_select_db($db_name);
if($db_check)
{
return true;
}
else
{
return false;
}
}
/*
* Wrap mysql_query function
*
* @param string $str SQL search query
* @return bool
*/
function query($str)
{
return mysql_query($str);
}
}
?>
我用的服务器是IIS的,请问各位大侠上述问题是什么原因导致的,该怎么解决啊?
------解决思路----------------------
你的php是什么版本?
错误提示是说mysql_connect 已废弃,将来还会被移除,用 mysqli 或者 PDO 代替。
你可以改错误提示级别来暂时缓解一下:
php.ini 中令:error_reporting=E_ALL & ~E_NOTICE & ~E_DEPRECATED
改完记得重启服务器才能生效。
------解决思路----------------------
好纳闷,自己都用PDO建立对象了,紧接着的下面一行竟然是mysql_connect!
这代码不是自己写的吧