Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL

Status
Not open for further replies.

viol8ion

Technical User
Feb 8, 2001
1,260
US
I am banging my head into the keyboard about now. My ISP switched servers this week, and switched my mySQL db also.

PHP4.2.2 & mySQL 3.23.45

Up until now I have written PHP3.. now I am thrust into 4, and dunno if this is where the problem is:

I have a PHP page that connects to mySQL db. That is working, and I can also access db via command line and edit, etc.. so db is fine. I accessed db via myPHPadmin vs 2.2 also, no prob. All data is intact.

My code, written in PHP3, which worked fine until the server switch, now throws this error:

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/viol8ion/public_html/rant.php3 on line 43

Here is the hook to the mySQL db with private info changed, of course:
<?php
$sql = &quot;SELECT * FROM rantitems&quot;;
$dbh=mysql_connect (&quot;localhost&quot;, &quot;me&quot;, &quot;my_password&quot;) or die ('I
cannot connect to the database.');
mysql_select_db (&quot;my_database&quot;);
$rs = mysql_db_query(&quot;my_database&quot;,$sql);
?>

Here is line 43:
while ($row = mysql_fetch_object($rs)) {

here is the page in question:

I know the answer is staring me in the face but it has been a long freaking weekend, and a long day... any ideas, anyone? Thanx When in doubt, deny all terms and defnitions.
 
you have a problem in the mysql_query.

the sintaxe is mysql_query($sql[,$dbh])

If you only use one connection to the DB, just do mysql_query($sql);

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Aniken,

Thanx for your quick reply. That did not make any difference. I did change it to $sql just for continuity, but I am conecting to db just fine. The problem is on line 43... here is the complete code for that section:

while ($row = mysql_fetch_object($rs)) {
$id = $row->id;
$title = $row->title;
$date = $row->date;
printf(&quot;<a href=\&quot;rantarticle.php3?id=%s\&quot;>%s</a><br>&quot;,$id,$title,$date);
}

This is just a simple loop that iterates thru the recordsets and creates a list on the dynamic page of links to news items that are in the db. The first line is line 43, which still comes up with the error:
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/viol8ion/public_html/rant.php3 on line 43


thanx again When in doubt, deny all terms and defnitions.
 
the problem is not in this piece of code, but before.

He is saying that $rs is not a valid mysql result, so the error is in the QUERY.

Check the query you are processing and you have your problem solved.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Okay, I finally got it... what a pain.

$dbh=mysql_connect was the proper syntax... I created another account to log into the mySQL db, used this syntax to log in, and that fixed the other error. Don't know why it would not access with my main login/pw but I am not going to argue.. I am fixed. thanx for your help. When in doubt, deny all terms and defnitions.
 
Having very recently gone through similar frustrations as you I've learned to stick in the &quot;error_log(mysql_error); function as a debugger immediately following most db actions during testing. A simple tail to the error.log file can tell quite a story.

It's usually the simple stupid stuff that gets us all in trouble.

Bob
 
Bob,

Good idea. My problem is that the action I was calling for was so simple I neglected to add anything extra. And to boot, the exact script worked before we moved the db and site to duplicate servers. Go figure.... When in doubt, deny all terms and defnitions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top