Home > Backend Development > PHP Tutorial > Four fetch statements in php

Four fetch statements in php

一个新手
Release: 2023-03-16 06:44:01
Original
7619 people have browsed it

Four fetch

First give a table

|-------man-------|
|-name-|-age---|
|--AA-- |--aa----|
|--BB-- |--bb----|
|--CC-- |--cc----|
|--CC-- |--dd----|
|-------------------|
Copy after login

sql query

$conn=mysqli_connect(...);//省略
$sql="select * from man";
$result=mysqli_query($conn,$sql);
Copy after login
mysqli_fetch_row($query)
返回【第一行/下一行】匹配记录,返回索引数组。执行mysqli_fetch_row($result),返回:Array([0]=>AA  [1] =>aa),这是第一次执行的情况。再执行一次,返回值变成:Array([0]=>BB [1]=>bb)
Copy after login
mysqli_fetch_array($query,arg )
arg取值范围:MYSQL_ASSOC、MYSQL_NUM、MYSQL_BOTH(默认)
返回【第一行/下一行】的匹配记录(与mysqli_fetch_row()一样)。
第二个参数取值:
1.MYSQL_BOTH(默认)
    返回的是关联数组和索引数组,执行mysqli_fetch_array($result),返回:Array([0]=>AA  [name]=>AA [1] =>aa [age]=>aa);再执行一次,返回:Array([0]=>BB  [name]=>BB [1] =>bb [age]=>bb)。
2.MYSQL_ASSOC
    返回关联数组,与mysqli_fetch_assoc()相同
3.MYSQL_NUM
    返回索引数组,此时的返回值与mysqli_fetch_row()相同
Copy after login
mysqli_fetch_assoc($query)
返回关联数组,第一次执行返回值:Array([name]=>AA [age]=>aa)
Copy after login
mysqli_fetch_object($query)
返回值是对象,而不是数组,第一次执行返回:sedClass Object([name]=>AA [age]=>aa)
Copy after login

The above is the detailed content of Four fetch statements in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template