<?php
/*
MySQL_DatabaseHandler.php, provides a DatabaseHandler implementation for
MySQL
Copyright (C) 2004 Arend van Beelen, Auton Rijnsburg
Copyright (C) 2004 Jelle Oosterhof
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For any questions, comments or whatever, you may mail me at: hide@address.com
*/
require_once('DatabaseHandler.php');
class MySQL_DatabaseHandler implements DatabaseHandler
{
public function connect($server, $database, $username, $password)
{
if(($this->handle = mysql_connect($server, $username, $password)) == false)
{
return false;
}
if(mysql_select_db($database, $this->handle) == false)
{
return false;
}
$this->server = $server;
$this->database = $database;
$this->username = $username;
return true;
}
public function disconnect()
{
mysql_close($this->handle);
}
public function type()
{
return 'MySQL';
}
public function server()
{
return $this->server;
}
public function database()
{
return $this->database;
}
public function username()
{
return $this->username;
}
public function query($sqlQuery)
{
$this->result = mysql_query($sqlQuery);
return ($this->result !== false);
}
public function error()
{
return mysql_error($this->handle);
}
public function numberOfRows()
{
return mysql_num_rows($this->result);
}
public function numberOfAffectedRows()
{
return mysql_affected_rows($this->handle);
}
public function hasResults()
{
return ($this->numberOfRows() > 0);
}
public function hasAffectedRows()
{
return ($this->numberOfAffectedRows() > 0);
}
public function result($row, $field)
{
return mysql_result($this->result, $row, $field);
}
public function resultArray()
{
return mysql_fetch_assoc($this->result);
}
public function resultObject()
{
return mysql_fetch_object($this->result);
}
public function resetResults()
{
return mysql_data_seek($this->result, 0);
}
public function insertId()
{
return mysql_insert_id($this->handle);
}
private $database;
private $handle;
private $result;
private $server;
private $username;
}
?>