Home > Backend Development > PHP Tutorial > An in-depth discussion of the PHP mysql_fetch_array() function_PHP Tutorial

An in-depth discussion of the PHP mysql_fetch_array() function_PHP Tutorial

WBOY
Release: 2016-07-15 13:33:29
Original
934 people have browsed it

We all know that

If the function is executed successfully, it will get a row of information (the row is obtained by executing the mysql_query() function) and return the row of information ;If it fails, no row will be returned.

PHP mysql_fetch_array() function syntax

mysql_fetch_array(data,array_type)

data is a necessary parameter, specify the data pointer to be used [data pointer ]. The data pointer is returned by requesting the mysql_query() function.

array_type is an optional parameter. Specifies the array type returned. The optional parameters are as follows:

* MYSQL_ASSOC - Associative array [Associative array]
*MYSQL_NUM - Numeric array [Numeric array]
* MYSQL_BOTH - Default value. Contains associative array [Associative array] and numeric array [Numeric array]

PHP mysql_fetch_array() function tips and points of attention

Note: When the specified data is obtained After that, the function will point to the next record; if the mysql_fetch_array() function continues to be requested, the next record will be returned.

Tip: The field names returned by the mysql_fetch_array() function will not be case-sensitive.

PHP mysql_fetch_array() function case

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>$</span><span class="attribute">con</span><span> = </span><span class="attribute-value">mysql_connect</span><span>("localhost", <br />"peter", "abc123");  </span></li><li class="alt"><span>if (!$con)  </span></li><li><span>{  </span></li><li class="alt"><span>die('Could not connect: ' . <br />mysql_error());  </span></li><li><span>}  </span></li><li class="alt"><span>$</span><span class="attribute">db_selected</span><span> = </span><span class="attribute-value">mysql_select_db<br /></span><span>("test_db",$con);  </span></li><li><span>$</span><span class="attribute">sql</span><span> = </span><span class="attribute-value">"SELECT * from Person <br />WHERE Lastname='Refsnes'"</span><span>;  </span></li><li class="alt"><span>$</span><span class="attribute">result</span><span> = </span><span class="attribute-value">mysql_query</span><span>($sql,$con);  </span></li><li><span>print_r(mysql_fetch_array($result));  </span></li><li class="alt"><span>mysql_close($con);  </span></li><li><span class="tag">?></span><span> </span></span></li></ol>
Copy after login

The above code will output the following results:

<ol class="dp-xml">
<li class="alt"><span><span>Array  </span></span></li>
<li><span>(  </span></li>
<li class="alt">
<span>[0] =</span><span class="tag">></span><span> Refsnes  </span>
</li>
<li>
<span>[LastName] =</span><span class="tag">></span><span> Refsnes  </span>
</li>
<li class="alt">
<span>[1] =</span><span class="tag">></span><span> Kai Jim  </span>
</li>
<li>
<span>[FirstName] =</span><span class="tag">></span><span> Kai Jim  </span>
</li>
<li class="alt">
<span>[2] =</span><span class="tag">></span><span> Taugata 2  </span>
</li>
<li>
<span>[Address] =</span><span class="tag">></span><span> Taugata 2  </span>
</li>
<li class="alt">
<span>[3] =</span><span class="tag">></span><span> 22  </span>
</li>
<li>
<span>[Age] =</span><span class="tag">></span><span> 22  </span>
</li>
<li class="alt"><span>)  </span></li>
</ol>
Copy after login

The above is the specific use of the PHP mysql_fetch_array() function.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446052.htmlTechArticleWe all know that if the function is executed successfully, it will get a row of information (the row is obtained by executing the mysql_query() function Obtained) and return the line information; if it fails, nothing will be returned...
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