Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use fetch in php

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to use fetch in php". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

In PHP, fetch refers to the fetch method for querying data. The commonly used fetch methods in PHP are mysqli_fetch_assoc, mysqli_fetch_row, mysqli_fetch_array, mysqli_fetch_object.

Operating environment: Windows 7, PHP 7.4, DELL G3

What does fetch mean in PHP?

The fetch in php refers to the fetch method for querying data.

The difference between the four fetches commonly used in PHP

In PHP, mysqli_fetch is often used to fetch data from the result set returned from the database, the most common being:

mysqli_fetch_assoc(),mysqli_fetch_row(),mysqli_fetch_array(),mysqli_fetch_object(), when used, differ as follows:

$publicMes = mysqli_fetch_assoc($res);var_dump($publicMes);

The results are as follows:

$a = mysqli_fetch_row($res); var_dump($a);

results are as follows

$b = mysqli_fetch_array($res); var_dump($b); echo $b[1]. ''; echo $b['user'];

The results are as follows:

$c = mysqli_fetch_object($res); var_dump($c);

The results are as follows:

Summary:

fetch_assoc() returns an associative array, using database fields as key values,

fetch_row() returns an indexed array, using index values,

fetch_array() returns an associative array, with both index numbers and fields, which can take values in both ways.

fetch_object() returns an object.

Note:

All fetches fetch data from the result set returned from the database only one at a time, the pointer moves down after fetching, and then fetches a new one next time, so you need to use the while loop to fetch all values. If you use a fetch before the loop, the data will be incomplete.

"How to use fetch in php" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report