12.30.2012

Connect MySql Database to Server

The connection of mysql database to server using object oriented concept, I uses these files:

  1. connection.php
  2. mysql.php
  3. index.php
So, Now let's start:

First of all create a root_folder that will contains all of files says: eshop
Now open your favorite text-editor like as Adobe Dreamweaver and create a php file names connection.php and save it in our root folder as eshop.

connection.php

<?php                                                   
define'DB_SERVER' , 'localhost' );
define'DB_USER' , 'root' );       
define'DB_PASSWORD' , '' );       
define'DB_NAME' , 'eshop_db' );   
?>                                  


Replace/change server, username, password and database_name as your default/desired setting.
And save it. That's over.

Now you think, What is benefit of make such a different file, we will make it separate with other php files?
Yes, you can do that but if we built a large php application like as eCommerce website then if these need to any change as change the database name etc. in future then it is quite easily to open connection.php file and replaced desired name rather then effect on rest of files.

No comments:

Post a Comment