zoukankan      html  css  js  c++  java
  • PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法

    这篇文章主要介绍了PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法,是在进行PHP数据库程序开发中常会遇到的错误,需要的朋友可以参考下
     

    本文实例讲述了PHP提示 Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法,在PHP程序开发中常会遇到这类问题。分享给大家供大家参考,具体的解决方法如下:

    将下面代码改为mysqli或PDO即可。

    1
    2
    3
    4
    5
    function connectit () {
    global $CFG;
    mysql_connect($CFG['db_host'], $CFG['db_user'], $CFG['db_pass']) or die(mysql_error());
    mysql_select_db($CFG['db_name']);
    }

    PDO:

    1
    $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);

    MYSQLI:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    $link = mysqli_connect(
     'localhost', /* The host to connect to 连接MySQL地址 */  
     'user',   /* The user to connect as 连接MySQL用户名 */  
     'password', /* The password to use 连接MySQL密码 */  
     'world');  /* The default database to query 连接数据库名称*/  
     
    if (!$link) {
      printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
      exit;
    }

    希望本文所述对大家的PHP程序设计有所帮助。

  • 相关阅读:
    UVa 820 因特网带宽(最大流)
    UVa 1001 奶酪里的老鼠(Dijkstra或Floyd)
    UVa 821 网页跳跃(Floyd)
    UVa 11624 大火蔓延的迷宫
    UVa 10881 蚂蚁
    UVa 11300 分金币
    UVa 11729 突击战
    《额尔古纳河右岸》读书笔记
    HDU 1083 Courses(二分图匹配模板)
    UVa 10618 跳舞机
  • 原文地址:https://www.cnblogs.com/favana/p/5443004.html
Copyright © 2011-2022 走看看