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, $argProvider=
'MSDASQL')
66 if (!empty($this->charPage))
67 $dbc =
new COM(
'ADODB.Connection',null,$this->charPage);
69 $dbc =
new COM(
'ADODB.Connection');
71 if (! $dbc)
return false;
74 if ($argProvider==
'mssql') {
77 $argProvider =
"SQLOLEDB";
83 if (!$argUsername) $argHostname .=
";Trusted_Connection=Yes";
84 }
else if ($argProvider==
'access')
85 $argProvider =
"Microsoft.Jet.OLEDB.4.0";
87 if ($argProvider) $dbc->Provider = $argProvider;
89 if ($argUsername) $argHostname .=
";$u=$argUsername";
90 if ($argPassword)$argHostname .=
";$p=$argPassword";
92 if ($this->
debug) ADOConnection::outp(
"Host=".$argHostname.
"<BR>\n version=$dbc->version");
94 @$dbc->Open((
string) $argHostname);
96 $this->_connectionID = $dbc;
99 return $dbc->State > 0;
103 function _pconnect($argHostname, $argUsername, $argPassword, $argProvider=
'MSDASQL')
105 return $this->
_connect($argHostname,$argUsername,$argPassword,$argProvider);
153 $dbc = $this->_connectionID;
155 $adors=@$dbc->OpenSchema(20);
157 $f = $adors->Fields(2);
158 $t = $adors->Fields(3);
159 while (!$adors->EOF){
160 $tt=substr($t->value,0,6);
161 if ($tt!=
'SYSTEM' && $tt !=
'ACCESS')
174 $table = strtoupper($table);
176 $dbc = $this->_connectionID;
178 $adors=@$dbc->OpenSchema(4);
181 $t = $adors->Fields(2);
182 while (!$adors->EOF){
185 if (strtoupper($t->Value) == $table) {
187 $fld =
new ADOFieldObject();
188 $c = $adors->Fields(3);
189 $fld->name = $c->Value;
191 $fld->max_length = -1;
192 $arr[strtoupper($fld->name)]=$fld;
200 return empty($arr) ? $false : $arr;
210 $dbc = $this->_connectionID;
216 if (!empty($this->charPage))
217 $oCmd =
new COM(
'ADODB.Command',null,$this->charPage);
219 $oCmd =
new COM(
'ADODB.Command');
220 $oCmd->ActiveConnection = $dbc;
221 $oCmd->CommandText =
$sql;
222 $oCmd->CommandType = 1;
226 while(list(, $val) = each($inputarr)) {
227 $type = gettype($val);
229 if ($type ==
'boolean')
230 $this->adoParameterType = 11;
231 else if ($type ==
'integer')
232 $this->adoParameterType = 3;
233 else if ($type ==
'double')
234 $this->adoParameterType = 5;
235 elseif ($type ==
'string')
236 $this->adoParameterType = 202;
237 else if (($val === null) || (!defined($val)))
240 $this->adoParameterType = 130;
243 $p = $oCmd->CreateParameter(
'name',$this->adoParameterType,1,$len,$val);
245 $oCmd->Parameters->Append($p);
248 $rs = $oCmd->Execute();
250 if ($dbc->Errors->Count > 0)
return $false;
254 $rs = @$dbc->Execute(
$sql,$this->_affectedRows, $this->_execute_option);
256 if ($dbc->Errors->Count > 0)
return $false;
257 if (!
$rs)
return $false;
259 if (
$rs->State == 0) {
269 if ($this->transOff)
return true;
271 if (isset($this->_thisTransactions))
272 if (!$this->_thisTransactions)
return false;
274 $o = $this->_connectionID->Properties(
"Transaction DDL");
275 $this->_thisTransactions = $o ? true :
false;
276 if (!$o)
return false;
278 @$this->_connectionID->BeginTrans();
279 $this->transCnt += 1;
286 if ($this->transOff)
return true;
288 @$this->_connectionID->CommitTrans();
289 if ($this->transCnt) @$this->transCnt -= 1;
293 if ($this->transOff)
return true;
294 @$this->_connectionID->RollbackTrans();
295 if ($this->transCnt) @$this->transCnt -= 1;
303 if (!$this->_connectionID)
return "No connection established";
304 $errc = $this->_connectionID->Errors;
305 if (!$errc)
return "No Errors object found";
306 if ($errc->Count == 0)
return '';
307 $err = $errc->Item($errc->Count-1);
308 return $err->Description;
313 $errc = $this->_connectionID->Errors;
314 if ($errc->Count == 0)
return 0;
315 $err = $errc->Item($errc->Count-1);
316 return $err->NativeError;
322 if ($this->_connectionID) $this->_connectionID->Close();
323 $this->_connectionID =
false;
342 var $hideErrors =
true;
346 if ($mode ===
false) {
347 global $ADODB_FETCH_MODE;
348 $mode = $ADODB_FETCH_MODE;
350 $this->fetchMode = $mode;
351 return $this->ADORecordSet($id,$mode);
359 $o=
new ADOFieldObject();
360 $rs = $this->_queryID;
361 $f =
$rs->Fields($fieldOffset);
364 $o->type = $this->MetaType($t);
365 $o->max_length = $f->DefinedSize;
375 if ($this->fetchMode & ADODB_FETCH_ASSOC)
return $this->fields[$colname];
377 $this->bind = array();
378 for ($i=0; $i < $this->_numOfFields; $i++) {
379 $o = $this->FetchField($i);
380 $this->bind[strtoupper($o->name)] = $i;
384 return $this->fields[$this->bind[strtoupper($colname)]];
390 $rs = $this->_queryID;
391 $this->_numOfRows =
$rs->RecordCount;
394 $this->_numOfFields = $f->Count;
401 $rs = $this->_queryID;
405 if ($this->_currentRow > $row)
return false;
406 @
$rs->Move((integer)$row - $this->_currentRow-1);
496 $t = $fieldobj->type;
497 $len = $fieldobj->max_length;
500 if (!is_numeric($t))
return $t;
513 if ($len <= $this->blobSize)
return 'C';
523 case 133:
return 'D';
526 case 135:
return 'T';
546 $rs = $this->_queryID;
548 $this->fields =
false;
551 $this->fields = array();
556 for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) {
557 $f =
$rs->Fields($i);
562 $this->_tarr = $tarr;
563 $this->_flds = $flds;
565 $t = reset($this->_tarr);
566 $f = reset($this->_flds);
568 if ($this->hideErrors) $olde = error_reporting(E_ERROR|E_CORE_ERROR);
569 for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) {
573 if (!strlen((
string)$f->value)) $this->fields[] =
false;
575 if (!is_numeric($f->value)) # $val = variant_date_to_timestamp($f->value);
577 $val=(float) variant_cast($f->value,VT_R8)*3600*24-2209161600;
580 $this->fields[] =
adodb_date(
'Y-m-d H:i:s',$val);
584 if ($val = $f->value) {
585 $this->fields[] = substr($val,0,4).
'-'.substr($val,4,2).
'-'.substr($val,6,2);
587 $this->fields[] =
false;
590 if (!strlen((
string)$f->value)) $this->fields[] =
false;
592 if (!is_numeric($f->value)) $val = variant_date_to_timestamp($f->value);
593 else $val = $f->value;
595 if (($val % 86400) == 0) $this->fields[] =
adodb_date(
'Y-m-d',$val);
596 else $this->fields[] =
adodb_date(
'Y-m-d H:i:s',$val);
600 $this->fields[] =
false;
603 ADOConnection::outp(
'<b>'.$f->Name.
': currency type not supported by PHP</b>');
604 $this->fields[] = (float) $f->value;
608 if(is_bool($f->value)) {
609 if($f->value==
true) $val = 1;
612 if(is_null($f->value)) $val = null;
614 $this->fields[] = $val;
617 $this->fields[] = $f->value;
621 $f = next($this->_flds);
622 $t = next($this->_tarr);
624 if ($this->hideErrors) error_reporting($olde);
627 if ($this->fetchMode & ADODB_FETCH_ASSOC) {
628 $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);
635 $rs = $this->_queryID;
636 $this->_queryID =
$rs->NextRecordSet();
638 if ($this->_queryID == null)
return false;
640 $this->_currentRow = -1;
641 $this->_currentPage = -1;
643 $this->fields =
false;
644 $this->_flds =
false;
645 $this->_tarr =
false;
647 $this->_inited =
false;
653 $this->_flds =
false;
654 @$this->_queryID->Close();
655 $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)