connecting to mysql using php
PHP and MySQL is one of the most preferred choice among open source web developers. Here is PHP script to open connection to MySQL database server.
$db_hostname = "SERVER_NAME";
$db_database = "DB_NAME";
$db_username = "DB_USER";
$db_password = "DB_USER_PASSWORD";
$cnn = mysql_pconnect($db_hostname, $db_username, $db_password) or die(mysql_error());
mysql_select_db($db_database, $cnn);
if ($cnn) {
echo 'Connected successfully';
}
mysql_close($cnn);
The above script will open the connection to MySQL from PHP, then it will select the requested database. Once the connection is establisted it will print "Connected Successfully". On the last line mysql_close( link identifier) is used to close the connection.
Closing connection is not neccessary as non-persistent open links are automatically closed at the end of the script's execution. You should still use it as best practice.