Blogger Information
Blog 5
fans 2
comment 1
visits 4634
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP中mysqli 操作数据库
zhihuanwang的博客
Original
633 people have browsed it

起步

由于mysql连接方式被废除,据说在php7中要使用mysql_connect()还需要额外下载组件。
使用mysqli有面向过程和面向对象两种方式。
mysqli提供了三个类:

mysqli 连接相关的

mysqli_result 处理结果集

mysqli_stmt 预处理类

数据库连接




<?
php$db_host = 'localhost';
$db_name = 'test';
$db_user = 'root';
$db_pwd = '';
//面向对象方式
$mysqli = new mysqli($db_host, $db_user, $db_pwd, $db_name);
//面向对象的昂视屏蔽了连接产生的错误,需要通过函数来判断
if(mysqli_connect_error()){    
    echo mysqli_connect_error();
}
//设置编码
$mysqli->set_charset("utf8");
//或者 $mysqli->query("set names 'utf8'")/
/关闭连接
$mysqli->close();
//面向过程方式的连接方式
$mysqli = mysqli_connect($db_host, $db_user, $db_pwd, $db_name);
//判断是否连接成功if(!$mysqli ){
    echo mysqli_connect_error();
}
//关闭连接
mysqli_close($mysqli);
?>


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!