Page 1 of 1

Not sure if this is a php or mysql config issue...

Posted: Mon Aug 02, 2004 11:42 pm
by abudabit
On my test server I was able to run a mysql query that involves an empty variable:

Code: Select all

   $result = mysql_query("SELECT * FROM classifieds WHERE adnumber = $adnumber LIMIT 1", $link_id);
   $query_data2 = mysql_fetch_object($result);


Where $adnumber is null (not just 0). Anyways, my test server ran these fine and just returned empty. On my main server though it returns this error:

Code: Select all

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/atomicde/public_html/profile.php on line 25


I guess I could recode to define the variables if they happen to be empty, but I am pretty used to (and my massive script has been tested around) the test server being able to "WHERE columnname = "

Is there a way to reconfig mysql/php to do this?

Posted: Tue Aug 03, 2004 6:20 am
by swirlee
It seems that the problem is that the query isn't returning any records, in which case you can't read its rows (since there are none) without getting an error.

The best practice is to check whether any rows were returned before trying to read them.

Re: Not sure if this is a php or mysql config issue...

Posted: Wed Aug 04, 2004 2:01 am
by WiZARD

Code: Select all

   $result = mysql_query("SELECT * FROM classifieds WHERE adnumber = $adnumber LIMIT 1", $link_id);
   @$query_data2 = mysql_fetch_object($result);
if (!$query_data2) {echo "sorry....";}