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

From: Date: Mon, 20 Oct 2003 13:55:44 +0000
Subject: Re: Using two colomns of mysql data as key/value pairs in arrays
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-31158@lists.php.net to get a copy of this message
> 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

« previous php.db (#31158) next »