| Current Path : /var/www/html/mmishra/indem/pks-ec/mbaentrance/website/includes/ |
| Current File : /var/www/html/mmishra/indem/pks-ec/mbaentrance/website/includes/database.class.php |
<?php
class database
{
private $connectlink; //Database Connection Link
private $username = "";//Database username
private $password = "";//Database password
private $database = "";// Database
private $hostname = "";// hostname
private $resultlink; //Database Result Recordset link
private $rows; //Stores the rows for the resultset
private $numRows;
//**--------------- To Connect mysql and Select Database -----------------**//
public function dbConnect($hostname,$username,$password,$database)
{
$this->hostname=$hostname;
$this->username=$username;
$this->password=$password;
$this->database=$database;
$this->connectlink = mysql_connect($this->hostname,$this->username,$this->password);
if(!($this->connectlink))
{
//throw new DatabaseConnectionException("Error Connecting to the Database".mysql_error(),"101");
echo "Faild"; exit;
}
else
{
mysql_select_db($this->database);
}
}
//**--------------- End-----------------**//
//**--------------- To Destroy mysql Connection -----------------**//
public function __destruct()
{
@mysql_close($this->connectlink);
}
//**--------------- End-----------------**//
//**--------------- To Execute mysql Query -----------------**//
public function query($sql)
{
$this->resultlink =mysql_query($sql) or die(mysql_error());
return $this->resultlink;
}
//**--------------- End-----------------**//
//**--------------- To Send Mail -----------------**//
public function send_mail($email_to,$subject,$message,$from_email,$from_name='',$html=false)
{
//echo $subject."<br>";exit;
if($from_name == '')
{
$from_name=$from_email;
}
$headers1= "";
if($html)
{
$headers1.= "Content-type: text/html; charset=iso-8859-1\r\n";
}
else
{
$headers1.= "Content-type: text/plain; charset=iso-8859-1\r\n";
}
$headers1.= "From: $from_email\r\n";
@mail($email_to,$subject,$message,$headers1);
}
//**--------------- End-----------------**//
//----------To Execute query-------//
public function executeQuery($query)
{
global $LOCAL_MODE;
global $SUPPORT_EMAIL;
global $SITE_SUPPORT;
global $SITE_FULL_NAME;
/*$temp = mysql_query($query) or die("<font size=2 color=red>You have an error(<font color=black>". mysql_error() . "</font>) in executing query : " . $query . " in file " . __FILE__ . " at line " . __LINE__ . "</font>");*/
if($LOCAL_MODE)
{
$temp = mysql_query($query) or die("<font size=2 color=red>You have an error(<font color=black>". mysql_error() . "</font>) in executing query : " . $query . " in file " . __FILE__ . " at line " . __LINE__ . "</font>");
}
else
{
$tm = mysql_query($query);
if($tm) {
$temp = $tm;
}
else {
$errMsg="There is an error encountered in ".$SITE_FULL_NAME."<br><font size=2 color=red>You have an error(<font color=black>". mysql_error() . "</font>) in executing query : " . $query . " in file " . __FILE__ . " at line " . __LINE__ . "</font> on Page : ".$_SERVER['PHP_SELF'];
$this->send_mail($SUPPORT_EMAIL,$subject='Error Message',$errMsg,$SITE_SUPPORT,'Error Message',$html=true);
header("location:mantinancePage.php");
exit();
}
}
return $temp;
}
//-------------end---------------//
//**--------------- To count no. of rows -----------------**//
public function num_rows($result)
{
$this->numRows = mysql_num_rows($result);
return $this->numRows;
}
//**--------------- end -----------------**//
//**--------------- To Get Record by passing Result Resource -----------------**//
public function fetch_rows($result)
{
$rows = array();
if($result)
{
while($row = mysql_fetch_array($result))
{
$row=$this->safe_output_array($row);
$rows[] = $row;
}
}
else
{
//throw new RetrieveRecordsException("Error Retrieving Records".mysql_error(),"102");
$rows = null;
}
return $rows;
}
function safe_output($value)
{
// Page output should look proper
$safe_value=htmlentities(stripslashes($value));
return $safe_value;
}
function safe_output_array($arr)
{
if(is_array($arr))
{
foreach($arr as $key => $value)
{
$result[$key]=$this->safe_output($value);
}
}
return $result;
}
//-------end------//
//**--------------- To Get Single Row -----------------**//
public function fetchSingleRow($result)
{
if($result)
{
$rows = mysql_fetch_array($result);
$rows=$this->safe_output_array($rows);
}
else
{
$rows = null;
}
return $rows;
}
//-------end------//
//**--------------- To get single result by Passing sql Query -----------------**//
public function getSingleResult($query)
{
$response = "";
global $LOCAL_MODE;
global $SUPPORT_EMAIL;
global $SITE_SUPPORT;
global $SITE_FULL_NAME;
if($LOCAL_MODE)
{
$result = mysql_query($query) or die("<center>An Internal Error has Occured. Please report following error to the webmaster.<br><br>".$query."<br><br>".mysql_error()."'</center>");
if ($line = mysql_fetch_array($result))
{
$response = $line[0];
}
}
else
{
$tm = mysql_query($query);
if($tm)
{
if ($line = mysql_fetch_array($tm))
{
$response = $line[0];
}
}
else
{
$errMsg="There is an error encountered in ".$SITE_FULL_NAME."<br><font size=2 color=red>You have an error(<font color=black>". mysql_error() . "</font>) in executing query : " . $query . " in file " . __FILE__ . " at line " . __LINE__ . "</font> on Page : ".$_SERVER['PHP_SELF'];
//send_mail($SUPPORT_EMAIL,$subject='Error Message',$errMsg,$SITE_SUPPORT,'Error Message',$html=true);
header("location:mantinancePage.php");
exit();
}
}
return $response;
}
}
//$db = new database(); //Create database object
?>