PHP / MySQL Connection Problem

Discussion in 'Web Design and Development' started by Neb Cross, May 23, 2009.

  1. Neb Cross macrumors newbie

    Joined:
    Oct 24, 2008
    #1
    Hello Everyone,

    I am running OS X version 10.5.6 and MySQL version 5.0.67

    I have enabled the inbuilt PHP and webserver which was pre-installed on my MAC. I did this using
    http://foundationphp.com/tutorials/php_leopard.php
    I can run basic PHP code, but i can not connect to MySQL through PHP.
    The code i use to connect to MySQL is:
    Code:
    <html>
    <body>
    <?php
    mysql_connect("localhost", "<username>", "<password>") or die(mysql_error());
    echo "Connected to MySQL<br />";
    ?>
    </body>
    </html> 
    
    However when i run this i get the following error on the web page:
    I would really appreciate any help :)
    Thanks in Advance and Regards,
    -Neb
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    This is why so many people end up just installing MAMP. These things can get annoying quick. Is the sock file where it's pointing at? I had a similar issue once and created a symbolic link to make sure it was point at the actual sock file. Also, were you following any particular MySQL setup guide?
     
  3. Neb Cross thread starter macrumors newbie

    Joined:
    Oct 24, 2008
    #3
    Hi angelwatt,

    Thanks for you reply. Honestly, i don't know if the sock file is where it's pointing at. Please could you give me details of how to find this out?

    Regarding mysql, i installed it a few months ago. So i wouldn't be able to tell you if i was following a set up guide, i cant remember. I do know that mysql does work. I can connect to it through the terminal. I have set up databases, tables and so on.

    Regards,
    -Neb
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    Simply by going to that folder location in either Finder or Terminal Unless you have Finder set to show hidden files you won't be able to get there in the normal fashion, but can (while on Finder) hit cmd+shift+g, which will bring up a prompt asking what folder to head to. Enter in /var/mysql and hit enter. It'll take you to the folder and you can look and see if the mysql.sock file is in there.

    If it's not there you'll want to find where it's at. You can use Finder to search out system files. Once found we can create a symbolic link for the sock. If you already have the folder /var/mysql/ then skip the first line below, but go along with the rest.

    Code:
    sudo mkdir /var/mysql
    sudo ln -s /path/to/actual/mysql.sock /var/mysql/mysql.sock
    sudo chown _mysql /var/mysql/mysql.sock
    sudo chmod 777 /var/mysql/mysql.sock
    (adapted from: http://andreys.info/node/273)
     

Share This Page