PHP - 使用标签而不是数组中的索引

I am fetching a row from a database using something like this

<?php
$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
$row = mysql_fetch_row($result);

echo $row[0]; // 42
echo $row[1]; // the email value
?>

This example shows accessing $row using an index, like $row[0], but this is a path to error. I would like to do it like $row['id'] or $row['email']... how is that possible?

Use mysql_fetch_assoc instead of mysql_fetch_row:

$row = mysql_fetch_assoc($result);

(That gives you the "associative array", so that you can fetch columns by their name.)

You can use mysql_fetch_assoc() instead of mysql_fetch_row()