Results 1 to 6 of 6

Thread: MySQL Database Connection error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    MySQL Database Connection error

    Hi,

    This question might sound elementary, or answered before. I have searched this forum's previous postings before asking this question. I followed the instructions given by some members on how to connect to the MySQL database. (http://www.vbforums.com/showpost.php...80&postcount=1)

    But when I run my script, I get the message below.

    Could not connect to the database; Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

    Could someone tell me what is wrong with my server please? Or am I doing something wrong still?

    Thanks,
    Menre

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: MySQL Database Connection error

    Please post your connection code.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Re: MySQL Database Connection error

    Hello,
    Thanks for you response to my message. The code that I am trying to connect to my database with is written below.

    Menre


    <?php

    define('SQL_HOST','localhost');
    define('SQL_USER','newman');
    define('SQL_PASS','yearone');
    define('SQL_DB','courses');


    $conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
    or die('Could not connect to the database; ' .mysql_error());


    mysql_select_db(SQL_DB, $conn)
    or die('Could not select database; ' . mysql_error());


    ?>

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: MySQL Database Connection error

    If you're running the MySQL server over TCP/IP you might need to add the port number to the host.

    PHP Code:
    define('SQL_HOST''localhost:3306'); 
    That should be the default, but it might be overridden to use sockets in some configuration file.

  5. #5
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: MySQL Database Connection error

    Also check that the mysql server is running.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Re: MySQL Database Connection error

    Thanks to everyone that responded to my question. I can now connect to the server and the database.

    MySQL was not running. That was the major cause of the problem. I also had to correct the code as someone suggested above.

    Once again, thanks.

    Menre

Posting Permissions

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



Click Here to Expand Forum to Full Width