15 if (!defined(
'ADODB_DIR'))
die();
17 define(
"_ADODB_ADO_LAYER", 1 );
42 $this->_affectedRows =
new VARIANT;
47 if (!empty($this->_connectionID)) $desc = $this->_connectionID->provider;
48 return array(
'description' => $desc,
'version' =>
'');
55 return $this->_affectedRows->value;
61 function _connect($argHostname, $argUsername, $argPassword,$argDBorProvider, $argProvider=
'')
69 $argDatabasename = $argDBorProvider;
71 $argDatabasename =
'';
72 if ($argDBorProvider) $argProvider = $argDBorProvider;
73 else if (stripos($argHostname,
'PROVIDER') ===
false)
74 $argProvider =
'MSDASQL';
82 if (!empty($this->charPage))
83 $dbc =
new COM(
'ADODB.Connection',null,$this->charPage);
85 $dbc =
new COM(
'ADODB.Connection');
87 if (! $dbc)
return false;
90 if ($argProvider==
'mssql') {
93 $argProvider =
"SQLOLEDB";
99 if (!$argUsername) $argHostname .=
";Trusted_Connection=Yes";
100 }
else if ($argProvider==
'access')
101 $argProvider =
"Microsoft.Jet.OLEDB.4.0";
103 if ($argProvider) $dbc->Provider = $argProvider;
105 if ($argProvider) $argHostname =
"PROVIDER=$argProvider;DRIVER={SQL Server};SERVER=$argHostname";
108 if ($argDatabasename) $argHostname .=
";DATABASE=$argDatabasename";
109 if ($argUsername) $argHostname .=
";$u=$argUsername";
110 if ($argPassword)$argHostname .=
";$p=$argPassword";
112 if ($this->
debug) ADOConnection::outp(
"Host=".$argHostname.
"<BR>\n version=$dbc->version");
114 @$dbc->Open((
string) $argHostname);
116 $this->_connectionID = $dbc;
119 return $dbc->State > 0;
120 }
catch (exception $e) {
121 if ($this->
debug) echo
"<pre>",$argHostname,
"\n",$e,
"</pre>\n";
128 function _pconnect($argHostname, $argUsername, $argPassword, $argProvider=
'MSDASQL')
130 return $this->
_connect($argHostname,$argUsername,$argPassword,$argProvider);
178 $dbc = $this->_connectionID;
180 $adors=@$dbc->OpenSchema(20);
182 $f = $adors->Fields(2);
183 $t = $adors->Fields(3);
184 while (!$adors->EOF){
185 $tt=substr($t->value,0,6);
186 if ($tt!=
'SYSTEM' && $tt !=
'ACCESS')
199 $table = strtoupper($table);
201 $dbc = $this->_connectionID;
203 $adors=@$dbc->OpenSchema(4);
206 $t = $adors->Fields(2);
207 while (!$adors->EOF){
210 if (strtoupper($t->Value) == $table) {
212 $fld =
new ADOFieldObject();
213 $c = $adors->Fields(3);
214 $fld->name = $c->Value;
216 $fld->max_length = -1;
217 $arr[strtoupper($fld->name)]=$fld;
233 $dbc = $this->_connectionID;
241 if (!empty($this->charPage))
242 $oCmd =
new COM(
'ADODB.Command',null,$this->charPage);
244 $oCmd =
new COM(
'ADODB.Command');
245 $oCmd->ActiveConnection = $dbc;
246 $oCmd->CommandText =
$sql;
247 $oCmd->CommandType = 1;
249 while(list(, $val) = each($inputarr)) {
250 $type = gettype($val);
252 if ($type ==
'boolean')
253 $this->adoParameterType = 11;
254 else if ($type ==
'integer')
255 $this->adoParameterType = 3;
256 else if ($type ==
'double')
257 $this->adoParameterType = 5;
258 elseif ($type ==
'string')
259 $this->adoParameterType = 202;
260 else if (($val === null) || (!defined($val)))
263 $this->adoParameterType = 130;
266 $p = $oCmd->CreateParameter(
'name',$this->adoParameterType,1,$len,$val);
268 $oCmd->Parameters->Append($p);
272 $rs = $oCmd->Execute();
274 if ($dbc->Errors->Count > 0)
return $false;
278 $rs = @$dbc->Execute(
$sql,$this->_affectedRows, $this->_execute_option);
280 if ($dbc->Errors->Count > 0)
return $false;
281 if (!
$rs)
return $false;
283 if (
$rs->State == 0) {
289 }
catch (exception $e) {
298 if ($this->transOff)
return true;
300 if (isset($this->_thisTransactions))
301 if (!$this->_thisTransactions)
return false;
303 $o = $this->_connectionID->Properties(
"Transaction DDL");
304 $this->_thisTransactions = $o ? true :
false;
305 if (!$o)
return false;
307 @$this->_connectionID->BeginTrans();
308 $this->transCnt += 1;
314 if ($this->transOff)
return true;
316 @$this->_connectionID->CommitTrans();
317 if ($this->transCnt) @$this->transCnt -= 1;
321 if ($this->transOff)
return true;
322 @$this->_connectionID->RollbackTrans();
323 if ($this->transCnt) @$this->transCnt -= 1;
331 if (!$this->_connectionID)
return "No connection established";
335 $errc = $this->_connectionID->Errors;
336 if (!$errc)
return "No Errors object found";
337 if ($errc->Count == 0)
return '';
338 $err = $errc->Item($errc->Count-1);
339 $errmsg = $err->Description;
340 }
catch(exception $e) {
347 $errc = $this->_connectionID->Errors;
348 if ($errc->Count == 0)
return 0;
349 $err = $errc->Item($errc->Count-1);
350 return $err->NativeError;
356 if ($this->_connectionID) $this->_connectionID->Close();
357 $this->_connectionID =
false;
376 var $hideErrors =
true;
380 if ($mode ===
false) {
381 global $ADODB_FETCH_MODE;
382 $mode = $ADODB_FETCH_MODE;
384 $this->fetchMode = $mode;
385 return $this->ADORecordSet($id,$mode);
393 $o=
new ADOFieldObject();
394 $rs = $this->_queryID;
395 if (!
$rs)
return false;
397 $f =
$rs->Fields($fieldOffset);
400 $o->type = $this->MetaType($t);
401 $o->max_length = $f->DefinedSize;
412 if ($this->fetchMode & ADODB_FETCH_ASSOC)
return $this->fields[$colname];
414 $this->bind = array();
415 for ($i=0; $i < $this->_numOfFields; $i++) {
416 $o = $this->FetchField($i);
417 $this->bind[strtoupper($o->name)] = $i;
421 return $this->fields[$this->bind[strtoupper($colname)]];
427 $rs = $this->_queryID;
430 $this->_numOfRows =
$rs->RecordCount;
431 }
catch (Exception $e) {
432 $this->_numOfRows = -1;
435 $this->_numOfFields = $f->Count;
442 $rs = $this->_queryID;
446 if ($this->_currentRow > $row)
return false;
447 @
$rs->Move((integer)$row - $this->_currentRow-1);
537 $t = $fieldobj->type;
538 $len = $fieldobj->max_length;
541 if (!is_numeric($t))
return $t;
554 if ($len <= $this->blobSize)
return 'C';
564 case 133:
return 'D';
567 case 135:
return 'T';
587 $rs = $this->_queryID;
589 $this->fields =
false;
592 $this->fields = array();
597 for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) {
598 $f =
$rs->Fields($i);
603 $this->_tarr = $tarr;
604 $this->_flds = $flds;
606 $t = reset($this->_tarr);
607 $f = reset($this->_flds);
609 if ($this->hideErrors) $olde = error_reporting(E_ERROR|E_CORE_ERROR);
610 for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) {
614 if (!strlen((
string)$f->value)) $this->fields[] =
false;
616 if (!is_numeric($f->value)) # $val = variant_date_to_timestamp($f->value);
618 $val= (float) variant_cast($f->value,VT_R8)*3600*24-2209161600;
621 $this->fields[] =
adodb_date(
'Y-m-d H:i:s',$val);
625 if ($val = $f->value) {
626 $this->fields[] = substr($val,0,4).
'-'.substr($val,4,2).
'-'.substr($val,6,2);
628 $this->fields[] =
false;
631 if (!strlen((
string)$f->value)) $this->fields[] =
false;
633 if (!is_numeric($f->value)) $val = variant_date_to_timestamp($f->value);
634 else $val = $f->value;
636 if (($val % 86400) == 0) $this->fields[] =
adodb_date(
'Y-m-d',$val);
637 else $this->fields[] =
adodb_date(
'Y-m-d H:i:s',$val);
641 $this->fields[] =
false;
645 $this->fields[] = (float) $f->value;
648 ADOConnection::outp(
'<b>'.$f->Name.
': currency type not supported by PHP</b>');
649 $this->fields[] = (float) $f->value;
653 if(is_bool($f->value)) {
654 if($f->value==
true) $val = 1;
657 if(is_null($f->value)) $val = null;
659 $this->fields[] = $val;
662 $this->fields[] = $f->value;
666 $f = next($this->_flds);
667 $t = next($this->_tarr);
669 if ($this->hideErrors) error_reporting($olde);
672 if ($this->fetchMode & ADODB_FETCH_ASSOC) {
673 $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);
680 $rs = $this->_queryID;
681 $this->_queryID =
$rs->NextRecordSet();
683 if ($this->_queryID == null)
return false;
685 $this->_currentRow = -1;
686 $this->_currentPage = -1;
688 $this->fields =
false;
689 $this->_flds =
false;
690 $this->_tarr =
false;
692 $this->_inited =
false;
698 $this->_flds =
false;
700 @$this->_queryID->Close();
701 }
catch (Exception $e) {
703 $this->_queryID =
false;
ADORecordSet_ado($id, $mode=false)
if(isset($_REQUEST['nrows'])) else $rs
_query($sql, $inputarr=false)
_connect($argHostname, $argUsername, $argPassword, $argProvider='MSDASQL')
adodb_date($fmt, $d=false, $is_gmt=false)
MetaColumns($table, $normalize=true)
MetaType($t, $len=-1, $fieldobj=false)
debug($variable='', $name=' *variable *', $line=' *line *', $file=' *file *', $recursiveDepth=3, $debugLevel=E_DEBUG)
_pconnect($argHostname, $argUsername, $argPassword, $argProvider='MSDASQL')
FetchField($fieldOffset=-1)
_connect($argHostname, $argUsername, $argPassword, $argDBorProvider, $argProvider='')