<?php
class cdbabstract {
var $_db_linkid = 0;
var $_db_qresult = 0;
var $rowdata = array();
var $nextrownumber = 0;
var $rowcount = 0;
function cdbabstract () {
die ("cdbabstract: do not create instances of cdbabstract! use a subclass.");
}
function open ($host, $user, $pass, $db = "") {
}
function close () {
}
function selectdb ($dbname) {
}
function query ($querystr) {
}
function seekrow ($row = 0) {
}
function readrow () {
}
function _ident () {
return "cdbabstract/1.1";
}
}
class cdbmysql extends cdbabstract {
function cdbmysql ($host, $user, $pass, $db = "") {
$this->open ($host, $user, $pass);
if ($db != "")
$this->selectdb($db);
}
function open ($host, $user, $pass) {
$this->_db_linkid = mysql_connect ($host, $user, $pass);
}
function close () {
@mysql_free_result($this->_db_qresult);
return mysql_close ($this->_db_linkid);
}
function selectdb ($dbname) {
if (@mysql_select_db ($dbname, $this->_db_linkid) == true) {
return 1;
}
else {
return 0;
}
}
function query ($querystr) {
$result = mysql_query ($querystr, $this->_db_linkid);
if ($result == 0) {
return 0;
}
else {
@mysql_free_result($this->_db_qresult);
$this->rowdata = array();
$this->_db_qresult = $result;
$this->rowcount = @mysql_num_rows ($this->_db_qresult);
if (!$this->rowcount) {
// the query was probably an insert/replace etc.
$this->rowcount = 0;
}
return 1;
}
}
function seekrow ($row = 0) {
if ((!mysql_data_seek ($this->_db_qresult, $row)) or ($row > $this->rowcount-1)) {
printf ("seekrow: cannot seek to row %d\n", $row);
return 0;
}
else {
return 1;
}
}
function readrow () {
if($this->rowdata = mysql_fetch_array ($this->_db_qresult)) {
$this->nextrownumber++;
return 1;
}
else {
return 0;
}
}
function _ident () {
return "cdbmysql/1.1";
}
}
?>