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
Re: MySQL Database Connection error
Please post your connection code.
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());
?>
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.
Re: MySQL Database Connection error
Also check that the mysql server is running.
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