doxn43207 2017-08-20 13:13
浏览 253
已采纳

MySQL错误信息,mysql_connect(),有什么方法可以修复它吗?

So this is the error message:

PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

This is the affected piece of code:

class wdClient {

    var $dbLink;                // The database link
    var $prefix;                // Table prefix
    var $script;                // The script running

    /**
     * Construct a new directory object.
     */
    function wdClient() {
        error_reporting(E_ALL ^ E_NOTICE);

        $this->prefix = WDDBPREFIX;

        // Connect to the database
        $this->dbLink = mysql_connect(WDDBHOST, WDDBUSER, WDDBPASSWD);

        // Select the database
        mysql_select_db(WDDBNAME, $this->dbLink) or die('Sorry, The site is currently unavailable!');
    }

where WDDBPREFIX, WDDBHOST, WDDBUSER, WDDBPASSWD, WDDBNAME are already defined in a config file.

I have tried simply using mysqli_connect instead of mysql_connect but it's not working.

  • 写回答

2条回答 默认 最新

  • dongzhitao4839 2017-08-20 15:14
    关注

    Note: Never use MySQL, use this method!

    //MySQLi information
    
            $db_host     = "localhost";
            $db_username = "username";
            $db_password = "password";
    
            //connect to mysqli database (Host/Username/Password)
            $connection = mysqli_connect($db_host, $db_username, $db_password) or die("Error " . mysqli_error());
    
            //select MySQLi dabatase table
            $db = mysqli_select_db($connection, "table") or die("Error " . mysqli_error());
    

    Good luck!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 asp.textbox后台赋值前端不能显示什么原因
  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误