数据库db1中有标t1
mysqli_fetch_row:以索引数组的方式获取一条记录的数据
2. mysqli_fetch_assoc:以关联数组的方式获取一条记录的数据
var_dump(mysqli_fetch_assoc($result));// {id:'1',name:'Jack',age:'18'}
var_dump(mysqli_fetch_assoc($result));// {id:'2',name:'Tom',age:'20'}
var_dump(mysqli_fetch_assoc($result));// NULL
//返回的数据,array?
array(3) {
["id"]=>
string(1) "1"
["name"]=>
string(4) "Jack"
["age"]=>
string(2) "18"
}
array(3) {
["id"]=>
string(1) "2"
["name"]=>
string(3) "Tom"
["age"]=>
string(2) "20"
}
NULL
mysqli_fetch_array:以索引数组或关联数组的方式获取一条记录的数据,默认两种心事都返回
mysqli_fetch_array($result);索引数组和关联数组
mysqli_fetch_array($result,MYSQLI_ASSOC);// 关联数组
mysqli_fetch_array($result,MYSQLI_NUM);// 数字数组
var_dump(mysqli_fetch_array($result));
//结果
array(6) {
[0]=>
string(1) "1"
["id"]=>
string(1) "1"
[1]=>
string(4) "Jack"
["name"]=>
string(4) "Jack"
[2]=>
string(2) "18"
["age"]=>
string(2) "18"
}
mysqli_fetch_all:以索引数组或关联数组的方式获取全部记录的数据
mysqli_fetch_all($result)
mysqli_fetch_all($result,MYSQLI_ASSOC)
mysqli_fetch_all($result,MYSQLI_NUM)
var_dump(mysqli_fetch_all($result,MYSQLI_ASSOC));
//结果
array(2) {
[0]=>
array(3) {
["id"]=>
string(1) "1"
["name"]=>
string(4) "Jack"
["age"]=>
string(2) "18"
}
[1]=>
array(3) {
["id"]=>
string(1) "2"
["name"]=>
string(3) "Tom"
["age"]=>
string(2) "20"
}
}
int mysqli_num_rows ( mysqli_result $result ) :获取结果中行的数量
var_dump(mysqli_num_rows($result));//int(2)
mysqli_fetch_field:返回一个字段的信息
var_dump(mysqli_fetch_field($result));//id字段的信息
var_dump(mysqli_fetch_field($result));//name字段
var_dump(mysqli_fetch_field($result));age字段
var_dump(mysqli_fetch_field($result));false
mysqli_fetch_fields:返回所有字段的信息。