Re: mysql_query returning empty result after DELETE
| From: | Stan | Date: | Mon, 14 Sep 2009 11:58:04 +0000 |
| Subject: | Re: mysql_query returning empty result after DELETE | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-46500@lists.php.net to get a copy of this message | ||
OK.
If I change the test to "if(mysql_num_rows($thisRow) < 1)" it does what I
want.
I guess if I want to understand why False was returned originally (just
after I created the database) I need to start over.
Do I have 4 possible conditions here: 1) the mysql_query() function fails
and I get a PHP error, 2) the query fails at the server and I get False, or
3) the query doesn't fail at the server and I get "a result" that a) is
empty, or b) contains 1 or more rows? Yes.
Problem solved (my code was naive), understanding increased (my code won't
be naive in the future as regards mysql functions in PHP).
Thank you very much..
"Chris" <dmagick@gmail.com> wrote in message
news:4AAD74E5.3090505@gmail.com...
> Stan wrote:
> > I did a "DELETE FROM picture" where "picture" is a table in my
> > database.
>
> Because this deletes all your records - so doing a select afterwards
> will find nothing.
>
> > Afterward, this piece of code does not generate an error
> > ----------------------------------------------
> > try
> > {
> > $query = "SELECT * FROM picture p " .
> > "WHERE p.pictureFile='" . $pictureFile .
> > "'";
> > $thisRow =
> > mysql_query($query, $pictures_connection);
> > }
> > catch(Exception $e)
> > {
> > echo 'caught exception: ', $e->getMessage()."\n";
> > $result = False;
> > }
>
> an empty result set is fine - it means no records found. It will not
> generate an exception.
>
> I'm not sure when mysql will generate an exception either, mysql_query
> returns FALSE if the query fails (see
> http://www.php.net/mysql_query).
> You then have to use mysql_error to get the reason why it failed.
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>