note 46193 added to function.mysql-fetch-array

From: Date: Fri, 01 Oct 2004 19:41:41 +0000
Subject: note 46193 added to function.mysql-fetch-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-77700@lists.php.net to get a copy of this message
Be warn of a Notice error when using mysql_unbuffered_query and mysql_fetch_array. This will lead to that error : <?php $query = mysql_unbuffered_query( 'SELECT 1' ); if ( ( $result = mysql_fetch_array( $query ) ) === false ) { printf( 'Ouch : nothing to fetch in file %s on line %d', __FILE__, __LINE__ ); } else { $query2 = mysql_query( 'SELECT 2' ); /* etc */ } ?> The mysql_query will warn you with a strange message : <b>Notice</b>: mysql_query() : Function called without first fetching all rows from a previous unbuffered query in <b>%s</b> on line <b>%d</b> This will simply mean you'll have to free the results before using mysql_query (or mysql_unbuffered_query) : else statement should now be : <?php ... else { mysql_free_result( $query ); ... ?> Notice : doing this is usefull only when using mysql_fetch_array once a time (when you know there is only one row). Don't do it after a while : <?php while ( $result = mysql_fetch_array($query) ) ; ?> ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46193 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46193&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+46193&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77700) next »