Differences between mysql_fetch_array () and mysql_fetch_row () in PHP

Source: Internet
Author: User

Recently, I was working on a project for PHP-database interaction. I was eager to seek success. After imitating the example below, I started my work. I mistakenly wrote mysql_fetch_array into mysql_fetch_row, it is found that the returned array is in the form of Index => value, but the field name => value is clearly remembered.

 

1. The function prototype of mysql_fetch_array is

ArrayMysql_fetch_array(Resource$ Result[, Int$ Result_type= Mysql_both])

 

Returns an array that corresponds to the fetched row and moves the Internal Data Pointer ahead.

 

The type of returned array depends on howResult_typeIs defined. By usingMysql_both(Default), you'll get an array with both associative and number indices. UsingMysql_assoc, You only get associative indices (as mysql_fetch_assoc () works), usingMysql_num, You only get number indices (as mysql_fetch_row () works ).

 

2. this makes it clear that if different parameters are set, mysql_fetch_array () can implement the functions of mysql_fetch_row () and mysql_fetch_assoc (). The last two functions only accept the first parameter, the returned values are associative => value, Index => value arrays.

 

3. What is mysql_both? I tested it.

 

SQL: Select firstname, lastname from table where id = "c01 ";

$ Array = mysql_fetch_array ($ result, mysql_both );

$ Array [0] is the same as $ array ['firstname ']

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.