Re: [PHP4BETA] PHP4/PHP3 incompatability
| From: | zeev at zend dot com | Date: | Sat, 18 Dec 1999 03:15:08 +0000 |
| Subject: | Re: [PHP4BETA] PHP4/PHP3 incompatability | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-8118@lists.php.net to get a copy of this message | ||
On Fri, 17 Dec 1999, Jack Slocum wrote:
> This message was sent from Geocrawler.com by "Jack Slocum" <slocum@pacbell.net>
> Be sure to reply to that address.
>
> Is there any reason why this works in PHP3 and
> not php4? I have alot of code to update if this
> is not a bug:
>
> if($row = mysql_fetch_array($rs))
> {
> $recordId = $row["recordId"];
> }
> else
> {
> echo "Record not found";
> }
>
> Under php3 this is a valid way to check to see if
> your query return any results and fetch the row
> all in one step. In php4 it throws the following
> error:
>
> Warning: Supplied argument is not a valid MySQL
> result resource in db.php on line 27
>
> Is this a bug or a new feature? :-)
It's most probably neither; The query that was sent to the MySQL backend
was probably invalid, which caused mysql_query() to return false (instead
of a result handle), which in turn caused mysql_fetch_row() to display
this error.
In PHP 3.0, the warning would have been with different text, but it was
illegal to use mysql_fetch_row() to check whether your query was valid
there too. If your query was invalid, and mysql_query() returned false,
you can't use this 'false' as a valid MySQL result handle, and doing so
will generate a warning.
You should check the return value from mysql_query(), if it is false,
display mysql_error() to figure out why.
Zeev