config.php File - Common database connectivity code file for all files in PHP
Coding of config.php file in PHP
Now in this section of database connectivity code I’ll tell you how to write your config.php file to get rid off writing the connectivity code everywhere.
These simple examples will fascinate you towards PHP programming.
Here is the next example of PHP config file…
|
<?php $host=”HostName”; $username=”Username”; $pass=”password”; $conn = mysql_connect ($host, $username, $pass); if (! $conn) { die (”Connection could not be established!”); } else { echo “User root logged into to MySQL server “,$host,” successfully.”; } ?> |
This is the same code, which we used earlier to connect from database that means this database connectivity code can be saved separately as a common file for your PHP application.
You can call this common file to any of you PHP application file with the help of “include”.
Here is the example code of calling config.php into other files.
|
<?php include(“config.php”); ?> |