Newbie PHP/MySQL problem

Discussion in 'PHP' started by FutureCoder, Aug 28, 2007.

  1. #1
    Hello all.

    I'm working through PHP tutorials & trying to integrate MySql(open and manipulate MySQL db's). The problem is whenever I try to open a database and output results I just get blank pages. I suspect it is something to do with the 'mysql_connect("localhost")' not being able to connect but I'm not sure. I'm using PHP & MySql versions 5. I also suspect there's something that should be in the php.ini file that isn't but I don't know what it is.

    As you can tell I'm a real newbie!

    Any & all help to connect to MySQL would be greatly appreciated!
     
    FutureCoder, Aug 28, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Post your code. Or try setting these lines on top of the code and see if you get any more errors.
    
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    PHP:

    And add this at the end of your mysql_connect():
    
    mysql_connect('localhost') OR die(mysql_error());
    
    PHP:
     
    nico_swd, Aug 28, 2007 IP
  3. HotSauce

    HotSauce Peon

    Messages:
    615
    Likes Received:
    124
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Are you getting just blank pages, or there errors outputted on the pages?
    If you are getting no errors and just a blank page, then maybe you aren't actually fetching the rows and outputting them? that would be a newbie thing to do :p
     
    HotSauce, Aug 28, 2007 IP
  4. FutureCoder

    FutureCoder Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks Nico_swd & HotSauce!

    HotSauce, I had been getting nothing but blank pages to this time.

    Nico_Swd, your suggestion gave me at least something I can work with namely this:

    Fatal error: Call to undefined function mysql_connect() in C:\www\webroot\query1.php on line 3

    I'm still pluggin' away and more suggestions are definitely welcome!

    Thx

    FC
     
    FutureCoder, Aug 28, 2007 IP
  5. FutureCoder

    FutureCoder Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    BTW here is the problem code:

    <?php error_reporting(E_ALL);
    ini_set('display_errors', '1');
    $db = mysql_connect("localhost") OR die(mysql_error());
    mysql_select_db("menagerie", $db);
    $query = "select * from animals";
    $result = mysql_query($query);
    $table = mysql_fetch_assoc($result);
    echo $table;
    ?>

    So I guess my question at this point is this: is the error saying mysql_connect() is undefined & if so why; or is something else going on?

    Thx again

    FC
     
    FutureCoder, Aug 28, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    You didn't install MySQL right, or it's not running. Did you install PHP and MySQL yourself? Or are you using something like XAMPP? (Which I'd suggest to use)
     
    nico_swd, Aug 28, 2007 IP
  7. FutureCoder

    FutureCoder Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I installed MySQL & PHP myself using WAMP.

    I am able to use the MySql Command Line just fine. That's how I learned MySql. So advise me on XAMPP(I just downloaded it)?

    I'm still having the same problem.

    Thx

    FC
     
    FutureCoder, Aug 29, 2007 IP
  8. ssanders82

    ssanders82 Peon

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hmm, I thought MySQL support was built into recent versions of PHP. Are you using it on Apache or IIS? Windows or Linux?
     
    ssanders82, Aug 29, 2007 IP
  9. FutureCoder

    FutureCoder Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    ssanders82

    I'm using Apache on Windows Vista(the home version not the 'Professional').
     
    FutureCoder, Aug 29, 2007 IP
  10. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Did you compile PHP with --with-mysql=/path/to/mysql ?
     
    Gordaen, Aug 29, 2007 IP