I can't connect, via PHP, to MySQL, please help

Discussion in 'PHP' started by tdnnash25, Sep 12, 2008.

  1. #1
    I'm a newb!

    I have apache2.2 running, have PHP installed and working.

    I tried saving a script named mysqltest.php in apache's htdocs directory, but when I try to go to http://localhost/mysqltest.php I get the error that the page cannot be found. I really need some help figuring this out.

    The content of my 'mysqltest.php' script is below:

    <html>
    <head> <title> MySQL Connection Test </title> </head>
    <body>
    <h2>

    <?php
    mysql_connect("localhost","user","password") or die(mysql_error());
    echo("Connected to MySQL");
    ?>

    </h2>
    </body> </html>


    I'm not exactly sure what should be set for "user", I remember setting a password when I installed mysql, does it just use the user that I'm signed into Windows with?

    I'm not sure that is the problem though, please help me out.
     
    tdnnash25, Sep 12, 2008 IP
  2. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #2
    If you have cPanel you can find out the mysql username / password there, or create antoher user if you forgot
     
    m0nkeymafia, Sep 12, 2008 IP
  3. Steve136

    Steve136 Peon

    Messages:
    240
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    As far as I can remember, the default user is "root". But can be changed via the MySQL command line.

    Regards,

    Steve
     
    Steve136, Sep 12, 2008 IP
  4. Gamernz

    Gamernz Active Member

    Messages:
    305
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #4
    If this is on your local computer then the user default should be 'root'.

    Good Luck.
     
    Gamernz, Sep 12, 2008 IP
  5. tdnnash25

    tdnnash25 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Okay, I changed it to root and set the password, but when I try to reach http://localhost/mysqltest.php I get an error that the page cannot be found

    Any ideas?
     
    tdnnash25, Sep 12, 2008 IP
  6. tdnnash25

    tdnnash25 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Okay, I'm having a different problem now. I'm getting HTTP 500 Internal Server error when trying to test connecting to mysql via php script.

    Can someone check my syntax to make sure I didn't screw something up?

    <?php
    mysql_connect("localhost","root","password") or die(mysql_error());
    echo"Connected to MySQL";
    ?>


    Am I missing any ()'s or anything else? I'm assuming root is the user since it was a default mysql install.
     
    tdnnash25, Sep 12, 2008 IP
  7. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #7
    HTTP 500 is a server error, it probably can be made with PHP but i believe it is caused by something else.

    First of all can you run any other script on your server?

    If yes then maybe your problem is .htaccess file in your directory, if you have one then try removing it and thn run your script.
     
    Greg Carnegie, Sep 13, 2008 IP
  8. thewebhostcompany

    thewebhostcompany Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    check the permissions on your script, make sure the script is readable and executable by all. 755 should do the trick.
     
    thewebhostcompany, Sep 13, 2008 IP