<?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);
}
}
|