MySQL connection before you can do anything with MySQL PHP, you must first establish a MySQL database connected to your web host. This is the connection function with MySQL.
MySQL connection
Before you can do anything with MySQL PHP, you must first create a MySQL database to connect to your web host. This is the connection function with MySQL.
MySQL localhost
If you are always on the internet, you will know that IP addresses are used as identifiers for computers and network servers. In this example, we assume that MySQL services are running scripts on the same machine.
When the PHP script and MySQL are on the same machine, you can use the local address to connect. 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 an IP address or URL to replace local. Please contact your web host for more details, if not working locally.
<? Php
Mysql_connect ("localhost", "admin", "1 admin") or die (mysql_error ());
Echo "Connected to MySQL <br/> ";
?>
Connected to MySQL
If you load the above PHP script to your web server, everything works normally, then you should see "connect to MySQL" display when you view. PHP page.
There are three arguments in the mysql_connect function. Server, user name, and password. In our example, the above arguments are:
Server-localhost
Username-admin
Password: 1 admin
The "or death (mysql..." code displays an error message if your browser-you may have guessed-there is an error in processing the connection! Check your username, password, or server carefully if you receive this error.