Login   Register  
PHP Classes
elePHPant
Icontem

File: connectDatabase.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of ajay prasad  >  Connect-database  >  connectDatabase.php  >  Download  
File: connectDatabase.php
Role: Example script
Content type: text/plain
Description: connectdatabase
Class: Connect-database
Connect to a MySQL database
Author: By
Last change:
Date: 2010-04-24 16:06
Size: 1,474 bytes
 

Contents

Class file image Download
<?php
    
/*
    *    class for database mysql connection 
    *
    *    ajay kumar prasad (ajai)
    *    copyright 2010 
    *    http://solutionsinfini.com
    */
    

?>    
<?php
    
class  DBConnect{
        
/////////////////////////////////////////////////
        // PRIVATE PROPERTIES  
        /////////////////////////////////////////////////
        
private $hostname$username$password$db_name$con;
        
        
/**
           * Constructor
           * @param String $hostname,$username,$password,$db_name. 
           * All information we need to provide whenever connect to db.
           */
            
public function __construct($hostname,$username,$password,$db_name){
            
$this->hostname $hostname;
            
$this->username $username;
            
$this->password $password;
            
$this->db_name $db_name;
        }
        
        
/**
       * Connect to MySQL.
       * @return void
       */
        
public function connectToMySQL(){
            
$this->con mysql_connect($this->hostname,$this->username,$this->password,$this->db_name);
            if(
$this->con){
            
mysql_select_db($this->db_name,$this->con);
             
//   echo "Connected sucessfully to MySQL .";
            
}
            else{
                die( 
"Could not connect to MySQL" mysql_error() . ".");
            }
        }
        
        
    
       function 
closeConnection(){
       
mysql_close($this->con);
    }
            
  }