PDA

View Full Version : MySQL/PHP head scratcher



Flying Mullet
02-01-2006, 02:41 PM
Okay, so I have my website running locally on MySQL and PHP (MySQL version 4.1.12a and PHP version 5.0.4) and everything runs just fine. I just uploaded some new code to the server, which is running MySQL version 4.0.25-standard and PHP version 4.3.10, and my code dies with the following error message:

<i>mysql_fetch_array(): supplied argument is not a valid MySQL result resource in xxxx.php on line 20</i>

Here's the code that I'm using:
<i><font size="1">// set up the database connection
$<i></i>db = my<i></i>sql_connect("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());;
mysql_se<i></i>lect_db("databasename",$d<i></i>b);

// query the DB for all characterspells
$s<i></i>ql = "SELECT `Level`, `Name`, `Description` FROM `characterspell`, `spell` WHERE `Character` = 'Celes' and `SpellName` = `Name` ORDER BY `Level` ";
$res<i></i>ult = mys<i></i>ql_query($s<i></i>ql);

// print the database results
wh<i></i>ile ($my<i></i>row = my<i></i>sql_fetch_array($re<i></i>sult))...</i></font>

I've checked the documentation for the methods that I'm using and all have been available since PHP version 3 so I would assum eit's not an issue of different versions of PHP. Any ideas?

Flying Mullet
02-01-2006, 05:11 PM
Never mind, I figured it out. Looks like my setup doesn't care about case-sensitivity where the server's setup does. Since my tables are called "CharacterSpell" and "Spell", locally "characterspell" and "spell" work but not on the server, since it's cave sensitive.

Samuraid
02-01-2006, 07:00 PM
Glad you figured it out. For future reference, you may want to do something like:

if (($result = @mysql_query($sql)) === false)
{
// Error message goes here using mysql_errno() and mysql_error()
}
So you can catch any errors before trying to fetch rows. Note: I'm not sure if that exact code will work, just pulled it off the top...I generally use my own custom SQL layer instead.