note 46193 rejected from function.mysql-fetch-array by betz
| From: | betz@php.net | Date: | Fri, 01 Oct 2004 20:48:24 +0000 |
| Subject: | note 46193 rejected from function.mysql-fetch-array by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77717@lists.php.net to get a copy of this message | ||
Note Submitter: baldurien at club-internet dot fr
----
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) ) ; ?>