<?php
$con=mysqli_connect("localhost","root","111111","student");//root是我的数据库名,111111是我的数据库密码名,student是数据库
if(!$con){
die("连接错误");}
echo "连接成功";
echo "<br>";
//插入一行数据
mysqli_query($con,"insert into stu(id,name,sex,address)values('1004','小花','女','上海')");
$result=mysqli_query($con,"select *from stu");
/*while($row=mysqli_fetch_array($result)){//也可以使用输出单个数组元素的方式
echo $row[0]." ".$row[1]." ".$row[2]." ".$row[3];
echo "<br>";
}*/
while($row=mysqli_fetch_array($result)){
echo "<pre>";
print_r($row);
}
mysqli_free_result($result);
mysqli_close($con);
?>
结果: