Heim  >  Artikel  >  Backend-Entwicklung  >  PHP提示Deprecated: mysql_connect(): The mysql extension is dep_PHP

PHP提示Deprecated: mysql_connect(): The mysql extension is dep_PHP

WBOY
WBOYOriginal
2016-05-31 19:30:21950Durchsuche

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

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

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:

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

MYSQLI:

$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程序设计有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn