MySQL Connection
Before you can do anything with MySQL PHP you must first establish a MySQL database connected to your Web page host. This is done with the MySQL connection feature.
MySQL localhost
If you have been around the Internet at the same time, you will know that IP addresses are used as identifiers for computers and Web servers. In this example of a connection script, we believe that the MySQL service is running on the same machine on the script.
When PHP scripts and MySQL are on the same machine, you can use the local address to connect to. Local is a shortcut, as long as the machine is connected to itself. If your MySQL service is running in a separate location, you need to insert the IP address or URL to replace the local. Please contact your web host for more details if the local is not working.
<?php
mysql_connect ("localhost", "admin", "1admin") or Die (Mysql_error ());
echo "Connected to mysql<br/>";
?>
Connected to MySQL
If you load the above PHP script into your Web server, everything works properly, then you should be able to see "Connect to MySQL" display when you view it. PHP page.
In the Mysql_connect function three arguments. Server, user name, and password. In our example above these arguments are:
Server-localhost
Username-admin
Password:1 Admin
That "or death (MySQL. .. "Code displays an error message if your browser-you may have guessed it-there is an error in processing the connection!" Carefully check your username, password or server if you receive this error.