Re: Using two colomns of mysql data as key/value pairs in arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Curious as to why you say you avoid mysql_fetch_array() like the plague. I
> use it frequently and am wondering if there is something wrong/not secure
> when using it or if there is a huge amount of overhead associated with its
> use.

It's not that it's not secure, just that it's bad to use any time you aren't using
specific key references.

Do the following to see the difference and you'll see why you'll almost always
want to use *_assoc() and not *_array():

<?
/**
 * Edit to suit your DB needs
 **/
$query = "SELECT * FROM blah";
$result = mysql( $dbname, $query );

echo '<pre>';
print_r( mysql_fetch_array( $result ));

echo "\n\n";
mysql_data_seek( $result, 0 );
print_r( mysql_fetch_assoc( $result ));

echo '</pre>';
?>

Especially if you use the foreach() construct, mysql_fetch_array() is bad 
news.

Chris

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux