<?
class db {
var $dbhost;
var $dbuser;
var $dbpass;
var $dbname;
var $dbtype="mysql";
var $dbobject;
function db () {
global $dbhost;
global $dbuser;
global $dbpass;
global $dbname;
switch ($this->dbtype) {
case 'mysql' :
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpass = $dbpass;
$this->dbname = $dbname;
$this->dbtype = "mysql";
$this->dbobject = new db_mysql($this->dbhost, $this->dbuser, $this->dbpass, $this->dbtype);
break;
default : $this->dbobject = new db_mysql($this->dbhost,$this->dbuser,$this->dbpass);
}
}
function db_connect () {
if ($this->dbobject->connect()) {
return true;
}
}
function db_disconnect () {
$this->dbobject->disconnect();
}
function is_connected(){
if ($this->dbobject->is_connected()) {
return true;
}
else {
return false;
}
}
function db_query($qry) {
$this->recordset = $this->dbobject->query($this->dbname,$qry);
}
function get_recordset_count(){
if ($this->recordset != null) {
return $this->dbobject->get_recordset_count($this->recordset);
}
else return 0;
}
function get_row(){
if ($this->recordset != null) {
return $this->dbobject->get_row($this->recordset);
}
else return null;
}
function recordset_seek($position){
if ($this->recordset != null) {
return $this->dbobject->recordset_seek($this->recordset,$position);
}
else return null;
}
function getHostName(){
return $this->dbhost;
}
function getUserName(){
return $this->dbuser;
}
function getPassword(){
return $this->dbpass;
}
function getDatabaseName(){
return $this->dbname;
}
function getLastRecord(){
return $this->dbobject->get_last_record();
}
}
class db_mysql extends db { // reserved for PHP 5.0 // implements dbtypes {
var $dbuser;
var $dbpass;
var $dbhost;
var $db_link;
function db_mysql($dbhost, $dbuser, $dbpass) {
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpass = $dbpass;
}
function connect() {
$this->db_link = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass)
or die( mysql_error() );
return true;
}
function disconnect() {
mysql_close($this->db_link);
}
function is_connected(){
if ($this->db_link) {
return true;
}
else {
return false;
}
}
function query($dbname,$qry) {
if ($this->is_connected()) {
$recordset = mysql_db_query($dbname,$qry);
return $recordset;
}
}
function get_recordset_count($recordset){
return mysql_num_rows($recordset);
}
function get_row($recordset){
return mysql_fetch_array($recordset);
}
function recordset_seek($recordset, $position){
return mysql_data_seek($recordset,$position);
}
function get_last_record(){
return mysql_insert_id();
}
}
?>