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

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 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统