<?
/******************************************************************************/
// Dbaccess class
// Author: Pierre-henri Delaval
// Mail: dev-center@guepe.com
// Date : 05/05/2000
// Version: 1.0
// Description:
//
// This class encapsulate the MetaBase class.
// Change the default host, user, pass, db to fetch you database settings
// or pass theses parameter each time you call the constructor
// Change the Type: to fetch your database ( ifx for informix here )
//
// Required:
// - MetaBase class by Manuel Lemos <mlemos@acm.org> at http://phpclasses.upperdesign.com/browse.html/package/20
// - a database supported by MetaBase
//
//
// I don't provide the sql script due to the fact that you probably use Mysql
/*****************************************************************************/
class Dbaccess {
var $numrow;
var $result;
var $error;
var $database;
var $row;
var $hostname;
var $username;
var $password;
var $dbname;
// Constructor:
// change the default host, user, pass, db to fetch you database settings
// or pass theses parameter each time you call the constructor
// Change the Type: to fetch your database ( ifx for informix here )
function Dbaccess ($host="hostname",$user="www",$pass="wwwpass",$db="dbname",$TextAsVarchar=1) {
$this->hostname = $host; $this->username= $user;
$this->password = $pass; $this->dbname = $db;
$this->row=0;
$this->error = MetabaseSetupDatabase(array(
"Type"=>"ifx",
"User"=>$this->username,
"Password"=>$this->password,
"Persistent"=>"0",
"Host"=>$this->hostname,
"Options"=>array(
"TextAsVarchar"=>$TextAsVarchar
)
),&$this->database);
if($this->error!="")
{
echo "Error while setting this->database access instance: $this->error";
print MetabaseError($this->database);
return (1);
}
else {
MetabaseSetDatabase ($this->database,$this->dbname);
return (0);
}
}
function GetNumRow () {
return $this->numrow;
}
function Get($variable) {
if ($this->numrow > 0):
return stripslashes(MetabaseFetchResult($this->database,$this->result,$this->row,$variable));
else :
return (0);
endif;
}
function NextRow() {
static $index_row=0;
if ($index_row > $this->numrow-1 ):
return false;
else:
$this->row = $index_row++;
return true;
endif;
}
function Query ($query_string) {
$this->result = MetabaseQuery($this->database,$query_string);
if (!$this->result) {
print "<BR>Query: $query_string failed<BR>";
print MetabaseError($this->database);
return (1);
}
else {
$this->numrow = MetabaseNumberOfRows($this->database,$this->result);
return (0);
}
}
function Insert ($query_string,$params = 0) {
$prepared_query = MetabasePrepareQuery($this->database,$query_string);
if (is_array($params)) {
for ($i=0;$i<count($params);$i++) {
MetabaseQuerySet($this->database,$prepared_query,$i+1,"text",$params[$i]);
}
}
$this->result = MetabaseExecuteQuery($this->database,$prepared_query);
if (!$this->result) {
print "<BR>Query: $query_string failed<BR>";
print MetabaseError($this->database);
return (1);
}
else {
$this->numrow = MetabaseNumberOfRows($this->database,$this->result);
return (0);
}
}
function SetMaxRow($size) {
$this->numrow = $size;
}
function Close() {
MetabaseCloseSetup($this->database);
}
}
?>
|