PHP Configuration File Coding

We should save the Database configuration details in a single file (ex: config.php). After that we can include it in All our necessary PHP scripts. In case we shift the server or need to modify any credentials mean we can update that detail in a single file else we need modify all the pages where we use the server connection.


Sample Code for Database Configuration:


//config.php

<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


mysql_select_db("DB_Name", $con);


?>
____________________________________________


//login.php


<?php
include("config.php");
?>



0 comments: