Connecting to SQL database using PHP

software development

#1

Please help!!

I’m new to MySQL and PHP but am keen to learn how to create a database-driven website so I have been reading and trying out a number of tutorials.

I have successfully set up a small database and a table using the PHPMyAdmin tools and was now hoping to display the contents of my database on a webpage. However when I try to connect to the database I get the following error:

Warning: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (111) in /home/.nariko/monox/clubmonox.com/display-reviews.php on line 2

Warning: MySQL Connection Failed: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (111) in /home/.nariko/monox/clubmonox.com/display-reviews.php on line 2

In the tutorials it claims you should use the following code to connect :-

mysql_connect(address, username, password);

replacing the address, username and password with the correct info. However I’m not sure what the address of my database is. I’ve tried using the hostname displayed in the Dreamhost panel and also tried leaving as “localhost”.

Where am I going wrong?


#2

I’m pretty new to php too but I’ve made the connection with this:

@ $db = mysql_connect(“mysql.somesite.com”, “username”, “password”);

The $db allows me to reference my database as variable $db.

Don’t forget the quotes and use the host name you set up. DON’T include the database name,
DONT DO: “mysql.somesite.com/mydatabase

Good luck!


#3

if this happened yesterday or today it might be that just MySQL server was down.

as for the dbase name go to your control panel click Goodies ->MySQL and check out the name of your dbase (it’ll be something like dbasename.yourdomain.com).
Don’t put ‘localhost’ because it won’t work that way… you have to specify the name of your dbase.