Re: Newbie alert: supplied argument is not a valid MySQL result resource
| From: | Matt Leonhardt | Date: | Wed, 11 Jul 2007 20:27:57 +0000 |
| Subject: | Re: Newbie alert: supplied argument is not a valid MySQL result resource | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-43771@lists.php.net to get a copy of this message | ||
""lameck kassana"" <chelaskk@gmail.com> wrote in message
news:967cd34f0707110248w50d29f31hde718e66e54c9e2a@mail.gmail.com...
> hey just make this
> $sid = mysql_fetch_array($query) or die ('Could not fetch from database:
>> ' ." mysql_error().");
> try this
Yep. I figured that out yesterday. Hit the nail right on the head. As
I've learned from experimentation, the pipe operator takes precedence to the
assignment operator so I was basically evaluating whether my query or a die
statement returned a true value (which the query statement was, so it never
processed the die()) and then assigning "true," or 1 to $query. The 'or'
operator by contrast processes after the assignment, so the following line:
$query = mysql_query("some SQL") or die();
first assigns a handle to $query (assuming the query is valid, which in my
case it was) and then evaluated the value of query. This leaves me with two
remaining questions. I'm coming from a Perl background, so I'm wondering if
there's a documentation page somewhere for PHP operators (something along
the likes of perlop) and as an experiment I tried the following code, and it
behaved exactly like the code I first posted, which I'm not sure why:
($query = mysql_query("valid SQL")) || die();
Shouldn't everything within the first set of parentheses here evaluate as
the first || condition?
Thanks for everyone's help,
Matt