|
-
May 5th, 2008, 04:12 PM
#1
Thread Starter
Addicted Member
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
-
May 5th, 2008, 11:13 PM
#2
Re: MySQL Database Connection error
Please post your connection code.
-
May 6th, 2008, 02:42 AM
#3
Thread Starter
Addicted Member
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());
?>
-
May 6th, 2008, 05:48 AM
#4
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.
-
May 6th, 2008, 09:12 AM
#5
Addicted Member
Re: MySQL Database Connection error
Also check that the mysql server is running.
-
May 9th, 2008, 01:35 AM
#6
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|