PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法
本文实例讲述了PHP提示Deprecated:mysql_connect():Themysqlextensionisdeprecated的解决方法,在PHP程序开发中常会遇到这类问题。分享给大家供大家参考,具体的解决方法如下:
将下面代码改为mysqli或PDO即可。
functionconnectit(){ global$CFG; mysql_connect($CFG['db_host'],$CFG['db_user'],$CFG['db_pass'])ordie(mysql_error()); mysql_select_db($CFG['db_name']); }
PDO:
$dbh=newPDO('mysql:host=localhost;dbname=test',$user,$pass);
MYSQLI:
$link=mysqli_connect( 'localhost',/*Thehosttoconnectto连接MySQL地址*/ 'user',/*Theusertoconnectas连接MySQL用户名*/ 'password',/*Thepasswordtouse连接MySQL密码*/ 'world');/*Thedefaultdatabasetoquery连接数据库名称*/ if(!$link){ printf("Can'tconnecttoMySQLServer.Errorcode:%s",mysqli_connect_error()); exit; }
希望本文所述对大家的PHP程序设计有所帮助。