php mysql 查询

 

抓取结果集对象中数据并且转换数组
$row = mysqli_fetch_assoc(结果集对象);
从结果集对象中抓取一行记录->转换关联数组
$row = mysqli_fetch_row(结果集对象);
从结果集对象中抓取一行记录->转换索引数组

例子:

<?php
//1:创建连接
$conn = mysqli_connect("127.0.0.1","root","","dangdang");
//2:设置编码
mysqli_query($conn,"SET NAMES UTF8");
//3:创建sql,发送sql
$sql = "SELECT * FROM dd_book";
$result = mysqli_query($conn,$sql);
//4:获取返回结果
//5:抓取一行记录 关联数组
while($row = mysqli_fetch_assoc($result)){
    echo $row['id'].$row['title'].'<br/>';
}
//6: 抓取一行记录,索引数组
//while($row = mysqli_fetch_row($result)){
//    echo $row[0].$row[1].'<br />';
//}

?>

 

posted @ 2017-05-09 19:02  快乐的咸鱼  阅读(784)  评论(0编辑  收藏  举报