韩顺平php利用Mysqli对数据库的查询(面向对象的方式)

<?php
//设置编码格式
header("content-type:text/html;charset=utf-8");

//Mysqli操作mysql数据库(面向对象风格)
//1.创建Mysql对象
$mysqli= new MySQLi("localhost","root","root","test");
if($mysqli->connect_error){
 die("连接失败".$mysql->connect_error);
}
//操作数据库(发送sql)
$sql="select*from user1";
//$res是结果集mysqli result
$res=$mysqli->query($sql);
//var_dump($res);
//3.处理结果相对于mysql_fetch_row();
while($row=$res->fetch_row()){
	foreach($row as $key=>$val){
		echo "--$val";
	
	
	}
echo "<br/>";

}
//关闭资源
//释放内存
$res->free();
//关闭连接
$mysqli->close();

?>

猜你喜欢

转载自blog.csdn.net/weixin_43345480/article/details/89706915