Table of Contents
The difference between PHP functions mysql_fetch_row, assoc, array and object
Home Backend Development PHP Tutorial Differences between PHP functions mysql_fetch_row, assoc, array, and object_PHP tutorial

Differences between PHP functions mysql_fetch_row, assoc, array, and object_PHP tutorial

Jul 13, 2016 am 10:07 AM
array fetch mysql object php function the difference of

The difference between PHP functions mysql_fetch_row, assoc, array and object

1. mysql_fetch_row

This function takes a row from the result set as enumeration data, obtains a row of data from the result set associated with the specified result identifier, and returns it as an array. Each result column is stored in a cell of the array, starting at offset 0.

Note that the offset here starts from 0, which means that the field name cannot be used to obtain the value, only the index can be used to obtain the value. For example:

while($row = mysql_fetch_row($res)){

echo $row['cid'].'>>>'.$row[1].'
';

 }

The value of $row['cid'] here cannot be obtained, but $row[1] can.

2. mysql_fetch_assoc

Get a row from the result set as an associative array, which means that this function cannot use the index to get the value like mysql_fetch_row, but can only use the field name to get the value. For example:

while($row = mysql_fetch_assoc($res)){

echo $row['cid'].'>>>'.$row[1].'
';

 }

Here $row[1] cannot get the value, but $row['cid'] can.

3. mysql_fetch_array

Get a row from the result set as an associative array, or a numeric array, or both. In addition to storing the data in the array as a numeric index, you can also store the data as an associative index, using the field name as the key. name.

That is to say, the result he gets is like an array, and the value can be obtained by key or index. For example:

while($row = mysql_fetch_array($res)){

echo $row['cid'].'>>>'.$row[1].'
';

 }

Here $row['cid'] and $row[1] can get corresponding values.

The functions of mysql_fetch_row and mysql_fetch_assoc add up to mysql_fetch_array.

4. mysql_fetch_object

As the name suggests, get a row from the result set as an object and use the field name as an attribute. So the only way to get the value is:

while($row = mysql_fetch_object($res)){

echo $row->cid.'>>>'.$row->title."
";

 }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/955270.htmlTechArticleDifferences between PHP functions mysql_fetch_row, assoc, array, and object 1. mysql_fetch_row This function takes a row from the result set as an enumeration Cite data from results associated with the specified result identifier...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

How to safely store JavaScript objects containing functions and regular expressions to a database and restore? How to safely store JavaScript objects containing functions and regular expressions to a database and restore? Apr 19, 2025 pm 11:09 PM

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

How does MySQL differ from Oracle? How does MySQL differ from Oracle? Apr 22, 2025 pm 05:57 PM

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

How to efficiently query large amounts of personnel data through natural language processing? How to efficiently query large amounts of personnel data through natural language processing? Apr 19, 2025 pm 09:45 PM

Effective method of querying personnel data through natural language processing How to efficiently use natural language processing (NLP) technology when processing large amounts of personnel data...

Popular science in the currency circle: What is the difference between decentralized exchanges and hybrid exchanges? Popular science in the currency circle: What is the difference between decentralized exchanges and hybrid exchanges? Apr 21, 2025 pm 11:30 PM

The difference between decentralized exchanges and hybrid exchanges is mainly reflected in: 1. Trading mechanism: Decentralized exchanges use smart contracts to match transactions, while hybrid exchanges combine centralized and decentralized mechanisms. 2. Asset control: Decentralized exchange users control assets, and mixed exchange ownership centralization and decentralization. 3. Privacy protection: Decentralized exchanges provide high anonymity, and hybrid exchanges require KYC in centralized mode. 4. Trading speed and liquidity: Decentralized exchanges are slower, liquidity depends on user pool, and hybrid exchanges are more fast and liquid in centralized mode. 5. Platform governance: Decentralized exchanges are governed by community governance, and hybrid exchanges are jointly governed by communities and centralized teams.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

See all articles