View Full Version : how to connect to MySQL Database

06-16-2009, 07:21 AM
i've reading and practicing a little with PHP and MySQL. i've set-up a local environment for the exercises. i've been fairly often using the code :

$connection = mysql_connect('localhost', 'root', 'pass') or die('unable to connect');
my problem is that, this code works fine in my local environment, but i don't know how the above code should be written to be able to connect to my database in the real world of the web? i know the 'root' should be replaced with the username while 'pass' should be replaced with the actual password of the username, but i'm wondering what i should replace 'localhost' with if i were to access the MySQL database in the on-line server? should i replace 'localhost' with 'http://some_domain_name.com/the_MySQL_folder' ?


06-16-2009, 07:35 AM
It can be 'localhost' if that is what has been configured, or it can be the DNS name of the mysql server, or it can be the IP address of the mysql server. Which one of these depends on how the web host has setup the web server/mysql server. The best way to determine which one would be to consult the web host's documentation.