PHP mysql_fetch_array():

I’m building a web app and my code works fine on my local machine while I’m running apache and mysql. However when I upload to my server, I get the following errors:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.alex/nwrcphoto/ on line 52

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.alex/nwrcphoto/ on line 60

I know the problem is not in my database as they are duplicated exactly and I went back through it with a fine toothed comb! Here are my lines of code:

$myYear2 = “SELECT DISTINCT(b.gYear), Year FROM lu_Year AS a LEFT JOIN tbl_Gallery AS b ON a.Y_ID=b.gYear WHERE b.gYear > 0 AND Show_ID = 1”;
$adoYear2 = mysql_query($myYear2);

while($YEAR1 = mysql_fetch_array($adoYear2)) {
^ this line is giving me the error. The other line is a duplicate. They are ‘$YEAR1, $adoYear2 etc’ because I’ve got the same statement twice because I have to do the loop twice.

Does anyone know why it works on my host machine (running EasyPHP) but not on Dreamhost?

Have you checked mysql_error() ?

:cool: [color=#6600CC]Atropos[/color] |

That’s your problem I bet. You likely don’t have the database connection details properly specified in your configuration file if you did a direct upload. I’ll bet money that the file is referencing the server “localhost” which won’t work on the DH machines. The first line throws no error because it returns false when you run a query without a valid db connection resource. mysql_fetch_array barfs because you’re passing it a blank string.

Is it Menalto’s Gallery2 that you’re running? Have you checked out the config file that’s on the server?

Join syntax changed with the introduction of MySQL 5.0.12, so you may want to check that.

Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]

while($YEAR1 = mysql_fetch_array($adoYear2)) {

On this line try

while($YEAR1 = @mysql_fetch_array($adoYear2)) {

some setups requre the @, could try $YEAR1 = mysql_fetch_object($adoYear2) also then Without breaking Double quotes could do a $YEAR1=>myfieldname

Thats my favorite way to do t … also may need to have the @ symbol before it.

hmm… ok, so I tried the mysql_error() but it doesn’t come up with anything. I tried putting the variable $YEAR and $YEAR1 inside of it. I tried echo "error: " . mysql_error() directly after the line and it doesn’t print anything out to the page. Am I missing something in syntax?

I know I have my configuration right, as I have both connections in my code, and I switch back and forth commenting them out. I’ve gone back and forth about 100 times and I know it’s connected to the right DB. When it’s not I get a different error.

As for the join syntax, I don’t believe it is in my sql statement because when I paste it exactly into phpmyadmin (on the server, not on my machine) it works just fine.

As for the @ symbol. I don’t come up with an error message, but it doesn’t print out my results to the page at all. I thougth that was kind of odd.

Thanks for all your replies! If you have any other ideas, or you notice me doing something wrong in my mysql_error(), let me know.

I recommend you modify the privileges on your DH hosted database so that you can interact with it from your home machine’s IP. Change the db configuration settings back and forth on your local machine and see if it works.

This will allow you to limit the problem domain to either PHP/web server settings, or MySQL issues. This will make it much easier for someone to help, or for you to identify the cause yourself.