前言
在PHP中执行SQL查询后,有人就不会读取数据库里面的内容,这里就写上三种读取数据库的方法
fetch_assoc方法
使用 fetch_assoc 方法获取关联数组。对于 SELECT 查询,可以使用 fetch_assoc 方法从结果集中获取下一行作为关联数组。每次调用 fetch_assoc 将返回结果集的下一行,直到没有更多行为止。
1 | // fetch_assoc方法 |
fetch_row方法
使用 fetch_row 方法获取索引数组。类似地,你也可以使用 fetch_row 方法从结果集中获取下一行作为索引数组。
1 | // fetch_row方法 |
fetch_array方法
使用 fetch_array 方法获取关联数组或索引数组。fetch_array 方法可以返回关联数组、索引数组或两者兼具的混合数组。你可以传递 MYSQLI_ASSOC、MYSQLI_NUM 或 MYSQLI_BOTH 作为参数来指定返回类型。
1 | // fetch_array方法 |