//1.创建MySQLi对象
echo "<meta charset=‘utf-8‘>";
$mysqli=new MySQLi("localhost","root","root","test");
if($mysqli->connect_error){
die("连接失败".$mysqli->connect_error);
}
//2.操作数据库(发送sql)
$sql="select *from user1";
$res=$mysqli->query($sql);
//3.处理结果
while($row=$res->fetch_row()){
foreach($row as $key=>$val){
echo "--$val";
}
echo "<br/>";
}
//4.关闭资源,连接
$res->free();
$mysqli->close();
时间: 2024-12-20 01:21:22