>  기사  >  백엔드 개발  >  The mysql extension is deprecated and will be removed in the future,这是什么原因啊该如何解决

The mysql extension is deprecated and will be removed in the future,这是什么原因啊该如何解决

WBOY
WBOY원래의
2016-06-13 12:10:001230검색

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!

这代码不是自己写的吧

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.