<?php
/*
************************************************************************
DbConnection.php -------------
Author : Imran Rahi
Begin : 14/01/2004
Email : hide@address.com
Purpose : database connection page
*************************************************************************
*/
?>
<?
class DbConnection
{
var $mDbName;
var $mDbHost;
var $mDbUser;
var $mDbPassword;
var $mConnection;
function DbConnection(){
$file = "dbconfig.php";
//read from the file
if(file_exists($file))
{
//read file line by line
$mFd = fopen ($file, "r");
$mCounter = 0;
while ($mCounter < 4) {
$mBuffer = fgets($mFd, 4096);
$mPos = strpos($mBuffer,"=");
$mBufferSub = substr($mBuffer,$mPos+1);
$mConfig[$mCounter] = trim($mBufferSub);
$mCounter++;
}
fclose ($mFd);
$this->mDbName = $mConfig[0] ; //"portal";
$this->mDbHost = $mConfig[1] ; //"m6";
$this->mDbUser = $mConfig[2] ; //"root";
$this->mDbPassword = $mConfig[3] ; //"";
$this->mConnection = mysql_connect($this->mDbHost, $this->mDbUser, $this->mDbPassword);
if(!$this->mConnection)
Die("Connection Failed");
}
else
die("No Config File is Available");
}
function ExecuteQuery($fQuery)
{
$mResult = mysql_db_query($this->mDbName, $fQuery, $this->mConnection);
return $mResult;
}
function NumRows($fResult)
{
$mRows = mysql_num_rows($fResult);
return $mRows;
}
function FetchArray($fResult)
{
$mRow = mysql_fetch_array($fResult);
return $mRow;
}
function FetchRow($fResult)
{
$mRow = @mysql_fetch_row($fResult);
return $mRow;
}
function AffectedRows()
{
$mRow = mysql_affected_rows();
return $mRow;
}
function FreeResult($fResult)
{
mysql_free_result($fResult);
}
}
?>