Config = new Config();
$this->HostName = $this->Config->Database['Host'];
$this->UserName = $this->Config->Database['User'];
$this->Password = $this->Config->Database['Password'];
$this->Schema = $this->Config->Database['Database'];
$this->Charset = $this->Config->Database['Charset'];
$this->ShowSQLQuery = $this->Config->Web['ShowSQLQuery'];
$this->ShowSQLError = $this->Config->Web['ShowSQLError'];
$this->open();
}
function open()
{
parent::connect($this->HostName, $this->UserName, $this->Password, $this->Schema);
$this->charset($this->Charset);
}
function query($Query)
{
if($this->ShowSQLQuery)
{
echo $this->ShowSQLQuery;
if(isset($_SERVER['REMOTE_ADDR'])) echo('
'.$Query.'
');
else echo($Query."\n");
}
$Result = parent::query($Query);
if(($this->error != '') and ($this->ShowSQLError))
{
if(isset($_SERVER['REMOTE_ADDR'])) echo('SQL Error: '.$this->error.'
'.$Query.'
');
echo('SQL Error: '.$this->error.' '.$Query."\n");
}
return($Result);
}
function select($Table, $What = '*', $Condition = 1)
{
return($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition));
}
function delete($Table, $Condition)
{
$this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition);
}
function insert($Table, $Data)
{
$Name = '';
$Values = '';
foreach($Data as $Key => $Value)
{
$Name .= ',`'.$Key.'`';
$Values .= ','.$Value;
}
$Name = substr($Name, 1);
$Values = substr($Values, 1);
$this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
}
function update($Table, $Condition, $Data)
{
$Values = '';
foreach($Data as $Key => $Value)
{
$Values .= ', `'.$Key.'`='.$Value;
}
$Values = substr($Values, 2);
$this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
}
function replace($Table, $Data)
{
$Name = '';
$Values = '';
foreach($Data as $Key => $Value)
{
$Name .= ',`'.$Key.'`';
$Values .= ','.$Value;
}
$Name = substr($Name, 1);
$Values = substr($Values, 1);
//echo('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES ('.$Values.')
');
$this->query('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
//echo($this->error().'
');
}
function charset($Charset)
{
$this->query('SET NAMES "'.$Charset.'"');
}
function TimeToMysqlDateTime($Time)
{
return(date('Y-m-d H:i:s', $Time));
}
function MysqlDateTimeToTime($Time)
{
$Parts = explode(' ', $Time);
$DateParts = explode('-', $Parts[0]);
$TimeParts = explode(':', $Parts[1]);
$Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]);
return($Result);
}
function MysqlDateToTime($Time)
{
return($this->MysqlDateTimeToTime($Time.' 0:0:0'));
}
}
?>