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 )
[ 0 ] Comments