Source for file adodb-ado5.inc.php
Documentation is available at adodb-ado5.inc.php
V4.97 22 Jan 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
Set tabs to 4 for best viewing.
Latest version is available at http://adodb.sourceforge.net
Microsoft ADO data driver. Requires ADO. Works only on MS Windows. PHP5 compat version.
define("_ADODB_ADO_LAYER", 1 );
/*--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------*/
var $adoParameterType = 201; // 201 = long varchar, 203=long wide varchar, 205 = long varbinary
var $_cursor_type = 3; // 3=adOpenStatic,0=adOpenForwardOnly,1=adOpenKeyset,2=adOpenDynamic
return array('description' => $desc, 'version' => '');
// you can also pass a connection string like this:
// $DB->Connect('USER ID=sa;PASSWORD=pwd;SERVER=mangrove;DATABASE=ai',false,false,'SQLOLEDB');
function _connect($argHostname, $argUsername, $argPassword,$argDBorProvider, $argProvider= '')
// - if $argProvider is empty, we assume that $argDBorProvider holds provider -- this is for backward compat
// - if $argProvider is not empty, then $argDBorProvider holds db
$argDatabasename = $argDBorProvider;
if ($argDBorProvider) $argProvider = $argDBorProvider;
else $argProvider = 'MSDASQL';
$dbc = new COM('ADODB.Connection',null,$this->charPage);
$dbc = new COM('ADODB.Connection');
if (! $dbc) return false;
/* special support if provider is mssql or access */
if ($argProvider== 'mssql') {
$u = 'User Id'; //User parameter name for OLEDB
$argProvider = "SQLOLEDB"; // SQL Server Provider
//if ($argDatabasename) $argHostname .= ";Initial Catalog=$argDatabasename";
//use trusted conection for SQL if username not specified
if (!$argUsername) $argHostname .= ";Trusted_Connection=Yes";
} else if ($argProvider== 'access')
$argProvider = "Microsoft.Jet.OLEDB.4.0"; // Microsoft Jet Provider
if ($argProvider) $dbc->Provider = $argProvider;
if ($argDatabasename) $argHostname .= ";DATABASE=$argDatabasename";
if ($argUsername) $argHostname .= ";$u=$argUsername";
if ($argPassword)$argHostname .= ";$p=$argPassword";
// @ added below for php 4.0.1 and earlier
@$dbc->Open((string) $argHostname);
function _pconnect($argHostname, $argUsername, $argPassword, $argProvider= 'MSDASQL')
return $this->_connect($argHostname,$argUsername,$argPassword,$argProvider);
adSchemaCharacterSets = 2,
adSchemaCheckConstraints = 5,
adSchemaConstraintColumnUsage = 6,
adSchemaConstraintTableUsage = 7,
adSchemaKeyColumnUsage = 8,
adSchemaReferentialContraints = 9,
adSchemaTableConstraints = 10,
adSchemaColumnsDomainUsage = 11,
adSchemaColumnPrivileges = 13,
adSchemaTablePrivileges = 14,
adSchemaUsagePrivileges = 15,
adSchemaSQLLanguages = 18,
adSchemaTranslations = 21,
adSchemaProviderTypes = 22,
adSchemaViewColumnUsage = 24,
adSchemaViewTableUsage = 25,
adSchemaProcedureParameters = 26,
adSchemaForeignKeys = 27,
adSchemaPrimaryKeys = 28,
adSchemaProcedureColumns = 29,
adSchemaDBInfoKeywords = 30,
adSchemaDBInfoLiterals = 31,
adSchemaHierarchies = 34,
$adors= @$dbc->OpenSchema(20);//tables
$f = $adors->Fields(2);//table/view name
$t = $adors->Fields(3);//table type
if ($tt!= 'SYSTEM' && $tt != 'ACCESS')
//print $f->value . ' ' . $t->value.'<br>';
$adors= @$dbc->OpenSchema(4);//tables
$t = $adors->Fields(2);//table/view name
$fld->type = 'CHAR'; // cannot discover type in ADO!
/* returns queryID or false */
function &_query($sql,$inputarr= false)
try { // In PHP5, all COM errors are exceptions, so to maintain old behaviour...
$oCmd = new COM('ADODB.Command',null,$this->charPage);
$oCmd = new COM('ADODB.Command');
$oCmd->ActiveConnection = $dbc;
$oCmd->CommandText = $sql;
foreach($inputarr as $val) {
// name, type, direction 1 = input, len,
//print $p->Type.' '.$p->value;
$oCmd->Parameters->Append($p);
if ($dbc->Errors->Count > 0) return $false;
if ($dbc->Errors->Count > 0) return $false;
if (! $rs) return $false;
return $true; // 0 = adStateClosed means no records returned
/* Returns: the last error message from previous database operation */
if (!$errc) return "No Errors object found";
if ($errc->Count == 0) return '';
$err = $errc->Item($errc->Count- 1);
$errmsg = $err->Description;
if ($errc->Count == 0) return 0;
$err = $errc->Item($errc->Count- 1);
return $err->NativeError;
/*--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------*/
var $_tarr = false; // caches the types
var $_flds; // and field objects
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
// returns the field object
$off= $fieldOffset+ 1; // offsets begin at 1
$f = $rs->Fields($fieldOffset);
$o->max_length = $f->DefinedSize;
//print "off=$off name=$o->name type=$o->type len=$o->max_length<br>";
/* Use associative array to get fields array */
// should only be used to move forward as we normally use forward-only cursors
// absoluteposition doesn't work -- my maths is wrong ?
// $rs->AbsolutePosition->$row-2;
@$rs->Move((integer) $row - $this->_currentRow- 1); //adBookmarkFirst
DBTYPE_RESERVED = 0x8000,
function MetaType($t,$len=- 1,$fieldobj= false)
$len = $fieldobj->max_length;
if ($len <= $this->blobSize) return 'C';
case 16: // adTinyInt = 16,
case 17: //adUnsignedTinyInt = 17,
case 18: //adUnsignedSmallInt = 18,
case 19: //adUnsignedInt = 19,
case 20: //adUnsignedBigInt = 21,
// time stamp not supported yet
// bind types and flds only once
//echo "<p>",$t,' ';var_dump($f->value); echo '</p>';
if (!is_numeric($f->value)) # $val = variant_date_to_timestamp($f->value);
// VT_DATE stores dates as (float) fractional days since 1899/12/30 00:00:00
$val= (float) variant_cast($f->value,VT_R8)* 3600* 24- 2209161600;
case 133: // A date value (yyyymmdd)
case 6: // currency is not supported properly;
$this->fields[] = (float) $f->value;
if($f->value== true) $val = 1;
if(is_null($f->value)) $val = null;
//print " $f->value $t, ";
@$rs->MoveNext(); // @ needed for some versions of PHP!
//$this->_queryID = $this->_QueryId->NextRecordSet();
if ($this->_queryID == null) return false;
@$this->_queryID->Close();// by Pete Dishman (peterd@telephonetics.co.uk)
|