mysql_query returning empty result after DELETE
mysql_query returning empty result after DELETE
am 13.09.2009 23:30:58 von Stan
I did a "DELETE FROM picture" where "picture" is a table in my database.
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;
}
----------------------------------------------
and testing $thisRow
----------------------------------------------
if(!$thisRow)
{
echo "picture '" . $pictureFile . "' does not exist in the
database.\n";
}
else
{
echo "picture '" . $pictureFile . "' exists in the database.\n";
$picture_table = array();
$picture_row = mysql_fetch_array($thisRow);
do /* capture row's picture data */
{
$picture_table[$picture_row["pictureHandle"]] = array(
"pictureName" => $picture_row["pictureName"],
"pictureFile" => $picture_row["pictureFile"],
"pictureMapFile" => $picture_row["pictureMapFile"],
"pictureDescription" => $picture_row["pictureDescription"],
"pictureDescriptionFile" =>
$picture_row["pictureDescriptionFile"],
"pictureDateTime" => $picture_row["pictureDateTime"],
"pictureOrientation" => $picture_row["pictureOrientation"],
"pictureStamp" => $picture_row["pictureStamp"]
) /* add this row to the table */;
} while(($picture_row = mysql_fetch_array($thisRow)));
print_r($picture_table) . "\n";
------------------------------------------------------------ ----
results in an empty array being printed ... implying that the query
was successful?
Help, please.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: mysql_query returning empty result after DELETE
am 14.09.2009 00:40:37 von dmagick
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/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: mysql_query returning empty result after DELETE
am 14.09.2009 13:36:40 von Stan
Yes. I deleted all records.
Prior to the DELETE, if I did a SELECT with specific criteria (WHERE
p.pictureFile = "some valid content"), and those criteria were not met,
mysql_query() returned False ... and, conversely, if those criteria were
met, mysql_query() returned "a resource" against which I could use
mysql_fetch() to retrieve the rows returned by the SELECT.
After the DELETE, and as I explained in my original post, the same SELECT
with specific criteria returns, not False as it should, but "a resource"
which contains an empty row.
If I look at the database using MySQL Query Browser, it appears empty.
I do not understand what is happening.
Help understanding what is happening is what I seek. Can you help?
Thanks.
"Chris" 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/
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: mysql_query returning empty result after DELETE
am 14.09.2009 13:58:04 von Stan
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" 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/
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: mysql_query returning empty result after DELETE
am 15.09.2009 00:55:38 von dmagick
Stan wrote:
> 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.
According to the docs mysql_query only returns false if there's an error.
> 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.
1) I'm not sure what you mean. If you try to run a query before having a
connection (or not checking the connection is valid before running a
query), then mysql_query will return false and php will throw warnings
or notices (can't remember which).
2) Correct
3) Also correct.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php