توابع mysql_fetch_assoc() PHP

تعریف و استفاده

توابع mysql_fetch_assoc() یک سطر از مجموعه نتایج را به عنوان یک آرایه مرتبط بازمی‌گرداند.

یک آرایه مرتبط را بر اساس سطرهایی که از مجموعه نتایج گرفته شده‌اند، بازمی‌گرداند، اگر سطرهای بیشتری وجود نداشته باشد، false را بازمی‌گرداند.

زبان

mysql_fetch_assoc(data)
Parameter Description
data Required. The data pointer to use. This data pointer is from the result returned by mysql_query().

Tips and notes

Note:mysql_fetch_assoc() and using mysql_fetch_array() with the second optional parameter MYSQL_ASSOC are completely the same. It only returns an associative array. This is also the initial working method of mysql_fetch_array().

Tip:If a numeric index is needed outside the associated index, use mysql_fetch_array().

Note:The field name returned by this function is case-sensitive.

Example

<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * from Person WHERE Lastname='Adams'";
$result = mysql_query($sql,$con);
print_r(mysql_fetch_assoc($result));
mysql_close($con);
?>

Output:

Array
(
[LastName] => Adams
[FirstName] => John
[City] => London
)