Board index   FAQ   Search  
Register  Login
Board index php forum :: Database MySQL Installation

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

Installation and configuration iussues

Moderators: macek, egami, gesf

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

Postby abudabit » Mon Aug 02, 2004 11:42 pm

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?
abudabit
New php-forum User
New php-forum User
 
Posts: 17
Joined: Sat May 29, 2004 3:07 pm

Postby swirlee » Tue Aug 03, 2004 6:20 am

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.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

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

Postby WiZARD » Wed Aug 04, 2004 2:01 am

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....";}
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol


Return to MySQL Installation

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.