query result warnings...

and another… lol :wink:

it’s a simple query which does work, however with a warning upon completion… the warning:

“Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in: yada yada”

the code…

[php]$query = “create table some_table(
id mediumint(8) unsigned auto_increment,
something varchar(20),
primary key (id) )”;

include(’…/connections/dbc.php’);

$result = @mysql_query($query) or die(“Query failed!” . mysql_error());
mysql_free_result($result);
mysql_close();[/php]

I’m pretty sure this warning will be transparent on the server I plan to put this code on, but does this really signify a problem or perhaps bad coding practice? :frowning:

I would remove the @ in front of the mysql_query. It may be surpressing a warning/notice/error on the query that effects the free_result.

CREATE queries might not create a result ressource. Actually, I think only SELECT queries generate those. Other queries simply return a code or an error as needed. Functions like mysql_error() or mysql_affected_rows() use the database link as the parameter and not the result ressource. To be sure about this, you can use var_dump() on the $result variable to see what it’s internal type is. If it’s not a ressource, it can’t be freed.

By the way, you don’t really need to free results as PHP does a clean up when ending. Unless you are dealing with massive amounts of data for long periods and have multiple queries in a sequence, I seriously doubt you will see any difference.

CREATE queries might not create a result ressource.

ah yes, that sounds to answer it… what made it all the more confuddling for me was recalling that it actually worked previously without the warning… but that sums it up nicely, so I’ll go take a var_dump and think things over innit… :-?

confuddling ?

Just wondering :D

lol did I say confuddle? :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service