1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
<?php
// change to wherever you stored adodb
require_once("adodb/adodb.inc.php");
// set fetch mode to associative arrays
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
// Part of the hack to get the db_fetch function to work
$_gaRows = array();
$_giCount = 0;
class PHPReportsDBI {
function db_connect($oArray) {
$sType = substr($oArray[2], 0, strpos($oArray[2], ":"));
$oArray[2] = substr($oArray[2], strpos($oArray[2], ":") + 1);
$oCon = ADONewConnection($sType);
$oCon->Connect($oArray[2], $oArray[0], $oArray[1], $oArray[3]);
if(!$oCon) {
die($oCon->ErrorMsg());
}
return $oCon;
}
function db_select_db($sDatabase) {
// Already taken care of in the $oCon->Connect() call
}
function db_query($oCon, $sSQL) {
$oRes = $oCon->Execute($sSQL);
if(!$oRes) {
die($oCon->ErrorMsg());
}
return $oRes;
}
function db_colnum($oRes) {
return $oRes->FieldCount();
}
function db_columnName($oRes, $iPos) {
$oField = $oRes->FetchField($iPos - 1);
return $oField->name;
}
function db_columnType($oRes, $iPos) {
$oField = $oRes->FetchField($iPos - 1);
return $oField->type;
}
function db_fetch($oRes) {
// needed nasty hack to get it to work
// adodb didnt like me calling $oRes->FetchRow()
// it would never move to the next row and it would infinate loop
global $_gaRows, $_giCount;
if($_gaRows == array()) {
$_gaRows = $oRes->GetArray();
$_giCount++;
return $_gaRows[0];
} else {
if($_giCount >= $oRes->RowCount()) {
return false;
}
$_giCount++;
return $_gaRows[$_giCount - 1];
}
}
function db_free($oRes) {
$oRes->Close();
return true;
}
function db_disconnect($oCon) {
$oCon->Close();
return true;
}
}
?>
|