PHP mysql_fetch_assoc() Function Example

PHP mysql_fetch_assoc() Function Example


Posted in : PHP Posted on : February 7, 2011 at 4:57 PM Comments : [ 0 ]

Using mysql_fetch_assoc() function we are find a row from the record set in the form of associate array.

PHP mysql_fetch_assoc() Function Example:

Using mysql_fetch_assoc() function we are find a row from the record set in the form of associate array. This function returns a row on success or false for failure.

Example:

<?php
$connection = mysql_connect("localhost","root","root");

if (!$connection) {
die('PHP Mysql database connection could not connect : ' . mysql_error());
}
else{ 
mysql_select_db("php_mysql", $connection);
$result = mysql_query("SELECT * FROM user", $connection);
print_r(mysql_fetch_assoc($result)); 
}
mysql_close($connection);
?>

In this example, we have used mysql_fetch_assoc() function to find a row from the record set.

The database "user" table records is:

After running this example the first row as output.

Output:

Array
( 
[user_id] => 3 
[user_name] => Deepak 
[user_email] => deepak@rediffmail.com 
[user_address] => Noida 
)

Download Example Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics