Results 1 to 3 of 3

Thread: MySQL/PHP head scratcher

  1. #1
    Old school, like an old fool. Flying Mullet's Avatar
    Join Date
    Apr 2003
    Location
    Napping in a peach tree.
    Posts
    19,185
    Articles
    6
    Blog Entries
    7
    Contributions
    • Former Administrator
    • Former Cid's Knight
    • Former Senior Site Staff

    Default MySQL/PHP head scratcher

    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?
    Last edited by Flying Mullet; 02-01-2006 at 02:50 PM.
    Figaro Castle

  2. #2
    Old school, like an old fool. Flying Mullet's Avatar
    Join Date
    Apr 2003
    Location
    Napping in a peach tree.
    Posts
    19,185
    Articles
    6
    Blog Entries
    7
    Contributions
    • Former Administrator
    • Former Cid's Knight
    • Former Senior Site Staff

    Default

    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.
    Figaro Castle

  3. #3
    Ominous Wanderer Tech Admin Samuraid's Avatar
    Join Date
    Oct 2001
    Posts
    5,522

    Default

    Glad you figured it out. For future reference, you may want to do something like:
    Code:
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •