// Dominion Libraries v.3.2 (c) 1999-2001 Philippe Thomassigny
// mail: metalwolf@parisfree.com , ICQ # 10079191
//
// 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.
// Modifications
// 13/07/2000 Ph. Thomassigny $_DEBUGDOMVAR_ variable programmed to debug queries
// 19/10/2000 Ph. Thomassigny Oracle Exec now return a 0 when error. (thanks to the comments of Anonymous)
// 02/02/2001 Ph. Thomassigny Login to mysql: if error say $this->Id = ""; instead of unset variable.
if (empty($__DOMVAR__))
{
$__DOMVAR__ = 1;
// Standard variables
define("ORACLE", 1);
define("POSTGRES", 2);
define("ODBC", 3);
define("MYSQL", 4);
define("INFORMIX", 5);
class DB_Base
{
var $Type;
var $Id;
function DB_Base($_Type = ORACLE)
{
$this->Type = $_Type;
}
function Logon($UN, $PW, $DB = "")
{
switch($this->Type)
{
case ORACLE:
$this->Id = OCILogon($UN, $PW, $DB);
break;
case POSTGRES:
$this->Id = pg_connect($DB); // $DB contains all the connect string
break;
case ODBC:
$this->Id = odbc_connect($DB, $UN, $PW);
break;
case MYSQL:
$this->Id = mysql_connect("localhost", $UN, $PW);
if ($this->Id && !mysql_select_db($DB, $this->Id))
{
mysql_close($this->Id);
$this->Id = "";
}
break;
case INFORMIX:
$this->Id = ifx_connect($DB, $UN, $PW);
break;
}
return $this->Id;
}
function LogOff()
{
switch($this->Type)
{
case ORACLE:
$ret = OCILogoff($this->Id);
break;
case POSTGRES:
$ret = pg_close($this->Id);
break;
case ODBC:
$ret = odbc_close($this->Id);
break;
case MYSQL:
$ret = mysql_close($this->Id);
break;
case INFORMIX:
$ret = ifx_close($this->Id);
break;
}
$this->Id = 0;
return $ret;
}
function Commit()
{
switch($this->Type)
{
case ORACLE:
return OCICommit($this->Id);
break;
case POSTGRES:
return true;
break;
case ODBC:
return odbc_commit($this->Id);
break;
case MYSQL;
return true;
break;
case INFORMIX:
return true;
break;
}
}
function Rollback()
{
switch($this->Type)
{
case ORACLE:
return OCIRollback($this->Id);
break;
case POSTGRES:
return true;
break;
case ODBC:
return odbc_rollback($this->Id);
break;
case MYSQL:
return true;
break;
case INFORMIX:
return true;
break;
}
}
}
class DB_Cursor
{
var $DB;
var $Cur;
var $Columns;
var $Item;
function DB_Cursor($_DB)
{
$this->DB = $_DB;
}
function Exec($_Sql)
{
if (isset($GLOBALS["_DEBUGDOMVAR_"]))
print "<br><b>$_Sql</b><br>\n";
switch($this->DB->Type)
{
case ORACLE:
$this->Cur = OCIParse($this->DB->Id, $_Sql);
if (OCIError($this->Cur))
return 0;
OCIExecute($this->Cur);
if (OCIError($this->Cur))
return 0;
break;
case POSTGRES:
$this->Cur = pg_exec($this->DB->Id, $_Sql);
$this->Item = 0;
break;
case ODBC:
$this->Cur = odbc_exec($this->DB->Id, $_Sql);
break;
case MYSQL:
$this->Cur = mysql_query($_Sql, $this->DB->Id);
break;
case INFORMIX:
$this->Cur = ifx_query($_Sql, $this->DB->Id);
break;
}
return $this->Cur;
}
function Fetch()
{
switch($this->DB->Type)
{
case ORACLE:
$ret = OCIFetchInto($this->Cur, &$this->Columns);
if (!$ret)
{ $this->Columns = 0;
return 0;
}
break;
case POSTGRES:
$this->Columns = @pg_fetch_row($this->Cur, $this->Item++);
break;
case ODBC:
$ret = odbc_fetch_into($this->Cur, 0, &$this->Columns);
if (!$ret)
{ $this->Columns = 0;
return 0;
}
break;
case MYSQL:
$this->Columns = mysql_fetch_row($this->Cur);
break;
case INFORMIX:
$this->Columns = ifx_fetch_row($this->Cur);
break;
}
return $this->Columns;
}
function Column($_i)
{
switch($this->DB->Type)
{
case ORACLE:
case POSTGRES:
case MYSQL:
return $this->Columns[$_i];
break;
case ODBC:
return odbc_result($this->Cur, $_i);
break;
return $this->Columns[$_i];
break;
case INFORMIX:
reset($this->Columns);
for ($i = 0; $i < $_i; $i ++)
{ next($this->Columns);
}
return current($this->Columns);
break;
}
}
function Close()
{
switch($this->DB->Type)
{
case ORACLE:
$ret = OCIFreeStatement($this->Cur);
$this->Cur = 0;
break;
case POSTGRES:
$ret = pg_freeresult($this->Cur);
$this->Cur = 0;
break;
case ODBC:
$this->Cur = 0;
return true;
break;
case MYSQL:
$this->Cur = 0;
return true;
break;
case INFORMIX:
$ret = ifx_free_result($this->Cur);
$this->Cur = 0;
break;
}
return $ret;
}
}
}