Simple PHP MYSQL connectivity question

  • Inn
  • Born
  • Born
  • Inn
  • Posts: 3

Post 3+ Months Ago

I need help with connecting to my database with php.

I cant establish a connection to the database to begin with...
I've found some help visiting sites that say you must use 'localhost' to connect to it:

mysql_connect('localhost, 'username', 'password')

In this case I know what username and password must be, but im confused with localhost.

These application are on my webhosts server...am I suppose to be using the word 'localhost', or is there some i.p. address or hostname that needs to be inserted in that field?

This is my error:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I've probably confused everyone with my wording, but any reply is very much appreciated.
Thanks
  • Viking[NO]
  • Newbie
  • Newbie
  • Viking[NO]
  • Posts: 5

Post 3+ Months Ago

If the application is on you webhost's server and the server is running a mysql database, then it is usually correct to use locahost as the hostname. You can also try the machine's host name, but most use localhost.
  • Inn
  • Born
  • Born
  • Inn
  • Posts: 3

Post 3+ Months Ago

Thanks for the reply Viking....

Turns out that the database is on a different server, so I emailed tech support for the name and they gave it to me, so all is good.
  • CartikaHosting
  • Proficient
  • Proficient
  • CartikaHosting
  • Posts: 455
  • Loc: Wishing I was in Kicking Horse

Post 3+ Months Ago

Hi Inn,

As a point of habit - you should not use localhost as your server name. Most good hosts will have their resources separated - ie clustered.

Therefore - you would want to use something along the lines of mysql.yourdomainname.com or mysql.yourhostsdomainname.com - or whatever naming feature they utilize for their DB server..

Even if your host is running all their reseources off of localhost - they may eventually grow and begin to cluster. If you havent named your resources properly - then, there will be extra steps involved on your part when and if your host finally clusters..

Hope this helps...
  • Inn
  • Born
  • Born
  • Inn
  • Posts: 3

Post 3+ Months Ago

I appreciate the tip Cartika, thanks.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 4 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.