Home  >  Article  >  Backend Development  >  PHP开发使用mysqli替代mysql

PHP开发使用mysqli替代mysql

WBOY
WBOYOriginal
2016-06-23 13:38:42798browse

在php+mysql开发过程中,遇到如下提示:

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead;

开发环境方面,Apach,PHP,Mysql为单独安装,未使用集成环境,版本如下:

PHP??5.6.3;

MySql??5.6.21-log;

使用mysqli替代mysql,代码如下。

原有mysql部分代码:

 1 // 连接数据库 2 $connection = mysql_connect("127.0.0.1:3306", "root", "root") or die("Can not connnect" . mysql_errno()); 3  4 // 设置编码格式,防止页面显示乱码 5 //mysql_query('set names utf8', $connection); 6  7 // 选择数据库 8 mysql_select_db("my_wiki", $connection); 9 10 // 查询数据库11 $sql = "select * from category";12 $result = mysql_query($sql);  

 

对应的mysqli代码:

1 // 连接数据库2 $connection = new mysqli("172.25.5.79:3306", "root", "root","discuz");3 4 // 设置编码格式,防止页面显示乱码5 $connection->query("SET NAMES utf8");6 7 //查询数据库8 $sql = "select * from category";9 $result = $connection->query($sql);

 

Statement:
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