PHP and MySQL (49 Blogs) Become a Certified Professional

How to Implement Mysql_fetch_array in PHP

Published on Sep 25,2019 12 Views


myMock Interview Service for Real Tech Jobs


myMock Interview Service for Real Tech Jobs

  • Mock interview in latest tech domains i.e JAVA, AI, DEVOPS,etc
  • Get interviewed by leading tech experts
  • Real time assessment report and video recording

Fetching data is an important aspect when it comes to PHP. In this article, we will understand the mysql_fetch_array method in the following order:


What is Mysql_fetch_array?

The function returns a row from a recordset as an associative array and a numeric array or both. The function gets a row from the mysql_query() function and it returns an array if it’s TRUE And when there is a failure or when there are no more rows then FLASE.


Mysql doesn’t have a Fetch array function. mysql_fetch_array is a PHP function that will allow you to access data stored in the result returned from the TRUE mysql_query if u want to know what is returned when you used the mysql_query function to query a Mysql database. It is not something that you can directly manipulate.



Data required which specifies data pointer to use and the data pointer is the result from the mysql_query() function

Array Types

Possible values are:

  • *mysql_assoc this is for an associative array
  • *mysql_num this is for a numeric array
  • *mysql_both this is for default or both



If (!$con)
Die(‘could not connect: ‘ .mysql_error());
$sql=”CHOOSE*from person where lastname=’ Refsnes’ ’’ ;





[0] => Refsnes

[lastname] => Refsnes

[1] =>seesee

[FirstName] => seesee



A Row of Data

The mysql_fetch_array function takes a Mysql query resource as an argument

($result)and it will return the first row of data returned by the mysql_query.




Getting Row data by mysql_fetch_array

Mysql_fetch_array will return the first row in a Mysql resource in the form of an associative array and columns of the MySQL result can be accessed by using the column names of the table.

PHP and MySQL Code for the above table

$query=”choose*from example”;
$result=mysql_query($query) or die (mysql_error());
$row=mysql_fetch_array($result) or die(mysql_error());




With this, we come to an end of this mysqql_fetch_array article. I hope you got an idea of how you can use the mysql_fetch_array method in PHP to get the desired data.

Check out the PHP Certification Training by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe.

Got a question for us? Please mention it in the comments section of this article and I will get back to you.


Browse Categories

Subscribe to our Newsletter, and get personalized recommendations.