PHP mysql_fetch_assoc() 函数
定义和用法
mysql_fetch_assoc() 函数从结果集中取得一行作为关联数组。
返回根据从结果集取得的行生成的关联数组,如果没有更多行,则返回 false。
语法
mysql_fetch_assoc(Data)
Parameter | Description |
---|---|
Data | Required. The data pointer to be used. This data pointer is from the result returned by mysql_query(). |
Tips and Notes
Note:mysql_fetch_assoc() is completely the same as using mysql_fetch_array() with the second optional parameter MYSQL_ASSOC. It simply returns an associative array. This is also the initial working method of mysql_fetch_array().
Tip:If you need a numeric index outside of the associated index, use mysql_fetch_array().
Note:The field names returned by this function are 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 )