Home > php教程 > php手册 > PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法,deprecated

PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法,deprecated

WBOY
Release: 2016-06-13 09:26:19
Original
1409 people have browsed it

PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法,deprecated

本文实例讲述了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']); 
} 
Copy after login

PDO:

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

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; 
}

Copy after login

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

mysql_connect(): The mysql extension is deprecated问题

参考答案我听不见彩虹出现的声音,我听不见太阳落下的声音.
 

调用PHP MYSQL的函数,出现的提示怎禁用

在php最上面写error_reporting(E_ALL & ~E_DEPRECATED);忽略错误
 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template