$link = mysqli_connect(“localhost”, “root”, “password”);
连接数据库
mysqli_select_db($link, “php”);
选择数据库“php”;
$sql = "SELECT * FROM admin ";
执行sql的语句;
r e s u l t = m y s q l i q u e r y ( result = mysqli_query( result=mysqliquery(link, $sql);
执行sql语句,对于对于增删改返回的是Boolean类型,对于查返回的是一个mysql结果集对象;
mysqli_fetch_array( r e s u l t ) ; 等 价 于 result);等价于 result);等价于result->fetch_array()
是一个迭代器,从结果集中选择第一行关联数组,也可以是索引数组, r o w , row, row,row[“user”]/$row[index]取得每一列,然后指针调整到下一个位置,当没有下一行的时候返回空
等价于输出下同;
mysqli_fetch_row($result);
与mysqli_fetch_array( r e s u l t ) ; 类 似 , 不 同 的 是 这 个 返 回 结 果 是 选 择 第 一 行 的 索 引 数 组 result);类似,不同的是这个返回结果是选择第一行的索引数组 result);类似,不同的是这个返回结果是选择第一行的索引数组row,用$row[index]取得每一列
mysqli_fetch_assoc($result);
类似于 r e s u l t − > f e t c h a r r a y ( ) , m y s q l i f e t c h r o w ( result->fetch_array(),mysqli_fetch_row( result−>fetcharray(),mysqlifetchrow(result);得到的是关联数组 r o w , 用 / row,用/ row,用/row[‘user’];得到
mysqli_fetch_object($result)
也是一个迭代器,与mysqli_fetch_array( r e s u l t ) ; 类 似 , 但 返 回 的 是 一 个 对 象 result);类似,但返回的是一个对象 result);类似,但返回的是一个对象obj,用 $row->user取得每一列
mysqli_free_result($result);
释放数据库查询结果
mysqli_close($link);
释放数据库连接
mysqli_num_rows($result);
返回查询结果集的行数
mysqli_num_fields($result);
返回查询结果集的列
mysqli_data_seek($result,n)
取得结果集中的第n+1行结果集,n+1不能超过结果行数,相当于取得二维数组结果集的第n个索引。
返回的也是一个结果集,通过 r o w = m y s q l i f e t c h a r r a y ( row=mysqli_fetch_array( row=mysqlifetcharray(result)才能得到结果
$link->error
得到数据库操作失败的信息;