PHP Doesn't see MySQL server :(
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: PHP Doesn't see MySQL server :(

  1. #1
    Senior Member
    Join Date
    Apr 2004
    Posts
    228

    Exclamation PHP Doesn't see MySQL server :(

    Hi!

    I'm trying to run an apache server from my system with PHP and MySQL.

    For some strange reason, PHP doesn't register that MySQL is running on my system. Going through tutorials didn't tell me much.

    Any pointers as to what should I look at?

    P.S. For "Google" people. I already searched and all I need is pointers for further searches
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  2. #2
    Member Christina's Avatar
    Join Date
    Sep 2002
    Location
    Ohio
    Posts
    63
    Check your config file...can you post the error?
    There are only two kinds of programming languages: those people always bitch about and those nobody uses.


  3. #3
    Senior Member
    Join Date
    Jul 2004
    Posts
    469
    What OS are the two running on? Are they on the same box? Are you sure MySQL is running? If its a linux type system try netstat -antp and look for mysql listening on a port. Other than that I think we need a little more information about how you have things setup.

  4. #4
    Senior Member
    Join Date
    Apr 2004
    Posts
    228
    Sorry my fault.

    They both run on the same XP machine.

    I tryed <? phpinfo(); ?>

    It doesn't show MySQL. Not sure what might be grong with them.

    I'm looking in to other things as well.
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  5. #5
    Senior Member
    Join Date
    Apr 2004
    Posts
    228
    Another thing.

    MySQL runs as Windows service. I can easily conect to it through the comand line
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  6. #6
    Member Christina's Avatar
    Join Date
    Sep 2002
    Location
    Ohio
    Posts
    63
    There are only two kinds of programming languages: those people always bitch about and those nobody uses.


  7. #7
    Senior Member
    Join Date
    Apr 2004
    Posts
    228
    Thanks for the tutorial, but I don't think it'll do me much good. the thing is that I can conect to the server if I'm conecting from the comand line. The problem is that PHP doesn't register MySQL server.

    I can't anderstand why
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  8. #8
    Senior Member
    Join Date
    Apr 2004
    Posts
    228
    OK. I got one of the tools running. It shows that PHP actualy does contact MySQL server. Only it doesn't seem to produce any output on the page.

    that's the code I use. IT should be alright. although a second opinion would be apriciated

    <html>
    <head>

    <titlte></title>

    </head>

    <body>
    <?php

    $host = "127.0.0.1:3306";
    $user = "php";
    $password = "*******";

    $connection = mysql_connect($host,$user,$password)
    or die ("Couldn't connect to a server");

    $db = mysql_select_db("tourism", $connection)
    or die ("Couldn't find database");

    $query ="SELECT FROM hotels";
    $result = mysql_query ($query)
    or die ("couldn't execute");

    if(!$result) die("Query Failed.");


    $num = mysql_numrows($result);
    mysql_close($connection);

    $count = 0;

    while ($count < $num) {

    $hotelID=mysql_result($result,$i,"Hotel_ID");
    $hotelName=mysql_result($result,$i,"Hotel_Name");

    echo "<b>$hotelID $hotelName</b";

    $count++;

    }
    ?>


    </body>

    </html>
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  9. #9
    Senior Member
    Join Date
    Apr 2004
    Posts
    228
    I also used "$host = "localhost";
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  10. #10
    Super Moderator
    Know-it-All Master Beaver

    Join Date
    Jan 2003
    Posts
    3,914
    Hey Hey,

    So it sounds to me like your mysql and php are playing quite well together.

    As far as phpinfo() goes, it doesn't connect to mysql... it's a function that displays statistics about your machine and php... It may tell you if php was built with --enable-mysql or whatever the configure option is, but that's about it.

    As far as your script, you've got errors in your mysql syntax... SELECT FROM hotels will not return any results... you must tell it which columns you wish to select... by specifying names (firstname, lastname, roomnumber... whatever you have in your database)... or by * to select all columns.

    Peace,
    HT
    IT Blog: .:Computer Defense:.
    PnCHd (Pronounced Pinched): Acronym - Point 'n Click Hacked. As in: "That website was pinched" or "The skiddie pinched my computer because I forgot to patch".

Posting Permissions

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