Database Connectivity – PHP and MySql
PHP database connectivity code – Below I am giving you the database connectivity code of PHP, this is what that will connect your PHP application with MySql database.
Here it ‘s …
|
<?php $host=”HostName”; $username=”UserName”; $pass=”password”; $conn = mysql_connect ($host, $username, $pass) or die (‘Database Connectivity Error‘); ?> |
This code is simply connecting your application to MySql Database without showing any detailed information about connection setting, But if you want to show the success or error message then write code in following way…
|
<?php $host=”HostName”; $username=”Username”; $pass=”password”; $conn = mysql_connect ($host, $username, $pass); if (! $conn) { die (”A connection to the Server could not be established!”); } else { echo “Root login”,$host,” successful.”; } ?> |
Either you can write the above-mentioned code on every page or can write a config.php that can be called on any page with the help of include method. In this way you can escape of writing code every time for connectivity.
Coding of config.php file in PHP