Oracle 5.0 Reference Manual page 2282

Table of Contents

Advertisement

mysql_fetch_assoc
Fetch a result row as an associative array
Warning
This extension is deprecated as of PHP 5.5.0, and will be removed in the
future. Instead, the
also
Alternatives to this function include:
mysqli_fetch_assoc
PDOStatement::fetch(PDO::FETCH_ASSOC)
Description
array mysql_fetch_assoc(
resource result);
Returns an associative array that corresponds to the fetched row and moves the internal data pointer
ahead.
mysql_fetch_assoc
the optional second parameter. It only returns an associative array.
Parameters
result
Return Values
Returns an associative array of strings that corresponds to the fetched row, or
more rows.
If two or more columns of the result have the same field names, the last column will take precedence.
To access the other column(s) of the same name, you either need to access the result with
numeric indices by using
mysql_fetch_array
Examples
Example 20.42. An expanded
<?php
$conn = mysql_connect("localhost", "mysql_user", "mysql_password");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("mydbname")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
$sql = "SELECT id as userid, fullname, userstatus
FROM
sometable
WHERE
userstatus = 1";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
Original MySQL API (Mysql)
MySQLi
MySQL: choosing an API
is equivalent to calling
The result resource that is being evaluated. This result comes from
a call to mysql_query.
mysql_fetch_row
description about aliases.
mysql_fetch_assoc
2262
or
PDO_MySQL
extension should be used. See
guide and
related FAQ
mysql_fetch_array
or add alias names. See the example at the
example
for more information.
with MYSQL_ASSOC for
if there are no
FALSE

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents