Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   1  <?php
   2  /**
   3  	 @version   v5.21.0  2021-02-27
   4  	 @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
   5  	 @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   6  
   7  	 Released under both BSD license and Lesser GPL library license.
   8  	 Whenever there is any discrepancy between the two licenses,
   9  	 the BSD license will take precedence.
  10  
  11  	 Set tabs to 4 for best viewing.
  12  
  13  	 Latest version is available at https://adodb.org/
  14  
  15  	 Requires ODBC. Works on Windows and Unix.
  16  
  17  	 Problems:
  18  	 	 Where is float/decimal type in pdo_param_type
  19  	 	 LOB handling for CLOB/BLOB differs significantly
  20  */
  21  
  22  // security - hide paths
  23  if (!defined('ADODB_DIR')) die();
  24  
  25  
  26  /*
  27  enum pdo_param_type {
  28  PDO::PARAM_NULL, 0
  29  
  30  /* int as in long (the php native int type).
  31   * If you mark a column as an int, PDO expects get_col to return
  32   * a pointer to a long
  33  PDO::PARAM_INT, 1
  34  
  35  /* get_col ptr should point to start of the string buffer
  36  PDO::PARAM_STR, 2
  37  
  38  /* get_col: when len is 0 ptr should point to a php_stream *,
  39   * otherwise it should behave like a string. Indicate a NULL field
  40   * value by setting the ptr to NULL
  41  PDO::PARAM_LOB, 3
  42  
  43  /* get_col: will expect the ptr to point to a new PDOStatement object handle,
  44   * but this isn't wired up yet
  45  PDO::PARAM_STMT, 4 /* hierarchical result set
  46  
  47  /* get_col ptr should point to a zend_bool
  48  PDO::PARAM_BOOL, 5
  49  
  50  
  51  /* magic flag to denote a parameter as being input/output
  52  PDO::PARAM_INPUT_OUTPUT = 0x80000000
  53  };
  54  */
  55  
  56  function adodb_pdo_type($t)
  57  {
  58  	 switch($t) {
  59  	 case 2: return 'VARCHAR';
  60  	 case 3: return 'BLOB';
  61  	 default: return 'NUMERIC';
  62  	 }
  63  }
  64  
  65  /*----------------------------------------------------------------------------*/
  66  
  67  
  68  class ADODB_pdo extends ADOConnection {
  69  	 var $databaseType = "pdo";
  70  	 var $dataProvider = "pdo";
  71  	 var $fmtDate = "'Y-m-d'";
  72  	 var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
  73  	 var $replaceQuote = "''"; // string to use to replace quotes
  74  	 var $hasAffectedRows = true;
  75  	 var $_bindInputArray = true;
  76  	 var $_genIDSQL;
  77  	 var $_genSeqSQL = "create table %s (id integer)";
  78  	 var $_dropSeqSQL;
  79  	 var $_autocommit = true;
  80  	 var $_lastAffectedRows = 0;
  81  
  82  	 var $_errormsg = false;
  83  	 var $_errorno = false;
  84  
  85  	 var $dsnType = '';
  86  	 var $stmt = false;
  87  	 var $_driver;
  88  	 
  89  	 /*
  90  	 * Describe parameters passed directly to the PDO driver
  91  	 *
  92  	 * @example $db->pdoOptions = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION];
  93  	 */
  94  	 public $pdoParameters = array();
  95  
  96  	function _UpdatePDO()
  97  	 {
  98  	 	 $d = $this->_driver;
  99  	 	 $this->fmtDate = $d->fmtDate;
 100  	 	 $this->fmtTimeStamp = $d->fmtTimeStamp;
 101  	 	 $this->replaceQuote = $d->replaceQuote;
 102  	 	 $this->sysDate = $d->sysDate;
 103  	 	 $this->sysTimeStamp = $d->sysTimeStamp;
 104  	 	 $this->random = $d->random;
 105  	 	 $this->concat_operator = $d->concat_operator;
 106  	 	 $this->nameQuote = $d->nameQuote;
 107  	 	 $this->arrayClass = $d->arrayClass;
 108  
 109  	 	 $this->hasGenID = $d->hasGenID;
 110  	 	 $this->_genIDSQL = $d->_genIDSQL;
 111  	 	 $this->_genSeqSQL = $d->_genSeqSQL;
 112  	 	 $this->_dropSeqSQL = $d->_dropSeqSQL;
 113  
 114  	 	 $d->_init($this);
 115  	 }
 116  
 117  	function Time()
 118  	 {
 119  	 	 if (!empty($this->_driver->_hasdual)) {
 120  	 	 	 $sql = "select $this->sysTimeStamp from dual";
 121  	 	 }
 122  	 	 else {
 123  	 	 	 $sql = "select $this->sysTimeStamp";
 124  	 	 }
 125  
 126  	 	 $rs = $this->_Execute($sql);
 127  	 	 if ($rs && !$rs->EOF) {
 128  	 	 	 return $this->UnixTimeStamp(reset($rs->fields));
 129  	 	 }
 130  
 131  	 	 return false;
 132  	 }
 133  
 134  	 // returns true or false
 135  	function _connect($argDSN, $argUsername, $argPassword, $argDatabasename, $persist=false)
 136  	 {
 137  	 	 $at = strpos($argDSN,':');
 138  	 	 $this->dsnType = substr($argDSN,0,$at);
 139  
 140  	 	 if ($argDatabasename) {
 141  	 	 	 switch($this->dsnType){
 142  	 	 	 	 case 'sqlsrv':
 143  	 	 	 	 	 $argDSN .= ';database='.$argDatabasename;
 144  	 	 	 	 	 break;
 145  	 	 	 	 case 'mssql':
 146  	 	 	 	 case 'mysql':
 147  	 	 	 	 case 'oci':
 148  	 	 	 	 case 'pgsql':
 149  	 	 	 	 case 'sqlite':
 150  	 	 	 	 case 'firebird':
 151  	 	 	 	 default:
 152  	 	 	 	 	 $argDSN .= ';dbname='.$argDatabasename;
 153  	 	 	 }
 154  	 	 }
 155  	 	 /*
 156  	 	 * Configure for persistent connection if required,
 157  	 	 * by adding the the pdo parameter into any provided
 158  	 	 * ones
 159  	 	 */
 160  	 	 if ($persist) {
 161  	 	 	 $this->pdoParameters[\PDO::ATTR_PERSISTENT] = true;
 162  	 	 } 
 163  	 	 
 164  	 	 try {
 165  	 	 	 $this->_connectionID = new \PDO($argDSN, $argUsername, $argPassword, $this->pdoParameters);
 166  	 	 } catch (Exception $e) {
 167  	 	 	 $this->_connectionID = false;
 168  	 	 	 $this->_errorno = -1;
 169  	 	 	 //var_dump($e);
 170  	 	 	 $this->_errormsg = 'Connection attempt failed: '.$e->getMessage();
 171  	 	 	 return false;
 172  	 	 }
 173  
 174  	 	 if ($this->_connectionID) {
 175  	 	 	 switch(ADODB_ASSOC_CASE){
 176  	 	 	 	 case ADODB_ASSOC_CASE_LOWER:
 177  	 	 	 	 	 $m = PDO::CASE_LOWER;
 178  	 	 	 	 	 break;
 179  	 	 	 	 case ADODB_ASSOC_CASE_UPPER:
 180  	 	 	 	 	 $m = PDO::CASE_UPPER;
 181  	 	 	 	 	 break;
 182  	 	 	 	 default:
 183  	 	 	 	 case ADODB_ASSOC_CASE_NATIVE:
 184  	 	 	 	 	 $m = PDO::CASE_NATURAL;
 185  	 	 	 	 	 break;
 186  	 	 	 }
 187  
 188  	 	 	 //$this->_connectionID->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_SILENT );
 189  	 	 	 $this->_connectionID->setAttribute(PDO::ATTR_CASE,$m);
 190  
 191  	 	 	 // Now merge in any provided attributes for PDO
 192  	 	 	 foreach ($this->connectionParameters as $options) {
 193  	 	 	 	 foreach($options as $k=>$v) {
 194  	 	 	 	 	 if ($this->debug) {
 195  	 	 	 	 	 	 ADOconnection::outp('Setting attribute: ' . $k . ' to ' . $v);
 196  	 	 	 	 	 }
 197  	 	 	 	 	 $this->_connectionID->setAttribute($k,$v);
 198  	 	 	 	 }
 199  	 	 	 }
 200  	 	 	 
 201  	 	 	 $class = 'ADODB_pdo_'.$this->dsnType;
 202  	 	 	 //$this->_connectionID->setAttribute(PDO::ATTR_AUTOCOMMIT,true);
 203  	 	 	 switch($this->dsnType) {
 204  	 	 	 	 case 'mssql':
 205  	 	 	 	 case 'mysql':
 206  	 	 	 	 case 'oci':
 207  	 	 	 	 case 'pgsql':
 208  	 	 	 	 case 'sqlite':
 209  	 	 	 	 case 'sqlsrv':
 210  	 	 	 	 case 'firebird':
 211  	 	 	 	 case 'dblib':
 212  	 	 	 	 	 include_once(ADODB_DIR.'/drivers/adodb-pdo_'.$this->dsnType.'.inc.php');
 213  	 	 	 	 	 break;
 214  	 	 	 }
 215  	 	 	 if (class_exists($class)) {
 216  	 	 	 	 $this->_driver = new $class();
 217  	 	 	 }
 218  	 	 	 else {
 219  	 	 	 	 $this->_driver = new ADODB_pdo_base();
 220  	 	 	 }
 221  
 222  	 	 	 $this->_driver->_connectionID = $this->_connectionID;
 223  	 	 	 $this->_UpdatePDO();
 224  	 	 	 $this->_driver->database = $this->database;
 225  	 	 	 return true;
 226  	 	 }
 227  	 	 $this->_driver = new ADODB_pdo_base();
 228  	 	 return false;
 229  	 }
 230  
 231  	function Concat()
 232  	 {
 233  	 	 $args = func_get_args();
 234  	 	 if(method_exists($this->_driver, 'Concat')) {
 235  	 	 	 return call_user_func_array(array($this->_driver, 'Concat'), $args);
 236  	 	 }
 237  
 238  	 	 return call_user_func_array('parent::Concat', $args);
 239  	 }
 240  
 241  	 // returns true or false
 242  	function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
 243  	 {
 244  	 	 return $this->_connect($argDSN, $argUsername, $argPassword, $argDatabasename, true);
 245  	 }
 246  
 247  	 /*------------------------------------------------------------------------------*/
 248  
 249  
 250  	function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
 251  	 {
 252  	 	 $save = $this->_driver->fetchMode;
 253  	 	 $this->_driver->fetchMode = $this->fetchMode;
 254  	 	 $this->_driver->debug = $this->debug;
 255  	 	 $ret = $this->_driver->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
 256  	 	 $this->_driver->fetchMode = $save;
 257  	 	 return $ret;
 258  	 }
 259  
 260  
 261  	function ServerInfo()
 262  	 {
 263  	 	 return $this->_driver->ServerInfo();
 264  	 }
 265  
 266  	function MetaTables($ttype=false,$showSchema=false,$mask=false)
 267  	 {
 268  	 	 return $this->_driver->MetaTables($ttype,$showSchema,$mask);
 269  	 }
 270  
 271  	function MetaColumns($table,$normalize=true)
 272  	 {
 273  	 	 return $this->_driver->MetaColumns($table,$normalize);
 274  	 }
 275  
 276  	public function metaIndexes($table,$normalize=true)
 277  	 {
 278  	 	 if (method_exists($this->_driver,'metaIndexes'))
 279  	 	 	 return $this->_driver->metaIndexes($table,$normalize);
 280  	 }
 281  
 282  	 /**
 283  	  * Return a list of Primary Keys for a specified table.
 284  	  *
 285  	  * @param string   $table
 286  	  * @param bool     $owner      (optional) not used in this driver
 287  	  *
 288  	  * @return string[]    Array of indexes
 289  	  */
 290  	public function metaPrimaryKeys($table,$owner=false)
 291  	 {
 292  	 	 if (method_exists($this->_driver,'metaPrimaryKeys'))
 293  	 	 	 return $this->_driver->metaPrimaryKeys($table,$owner);
 294  	 }
 295  
 296  	 /**
 297  	  * Returns a list of Foreign Keys for a specified table.
 298  	  *
 299  	  * @param string   $table
 300  	  * @param bool     $owner      (optional) not used in this driver
 301  	  * @param bool     $upper
 302  	  * @param bool     $associative
 303  	  *
 304  	  * @return string[] where keys are tables, and values are foreign keys
 305  	  */
 306  	public function metaForeignKeys($table, $owner=false, $upper=false,$associative=false) {
 307  	 	 if (method_exists($this->_driver,'metaForeignKeys'))
 308  	 	 	 return $this->_driver->metaForeignKeys($table,$owner,$upper,$associative);
 309  	 }
 310  
 311  	 /**
 312  	  * List procedures or functions in an array.
 313  	  *
 314  	  * @param $procedureNamePattern A procedure name pattern; must match the procedure name as it is stored in the database.
 315  	  * @param $catalog              A catalog name; must match the catalog name as it is stored in the database.
 316  	  * @param $schemaPattern        A schema name pattern.
 317  	  *
 318  	  * @return false|array false if not supported, or array of procedures on current database with structure below
 319  	  *         Array(
 320  	  *           [name_of_procedure] => Array(
 321  	  *             [type] => PROCEDURE or FUNCTION
 322  	  *             [catalog] => Catalog_name
 323  	  *             [schema] => Schema_name
 324  	  *             [remarks] => explanatory comment on the procedure
 325  	  *           )
 326  	  *         )
 327  	  */
 328  	public function metaProcedures($procedureNamePattern = null, $catalog  = null, $schemaPattern  = null) {
 329  	 	 if (method_exists($this->_driver,'metaProcedures'))
 330  	 	 	 return $this->_driver->metaProcedures($procedureNamePattern,$catalog,$schemaPattern);
 331  	 	 return false;
 332  	 }
 333  
 334  	function InParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)
 335  	 {
 336  	 	 $obj = $stmt[1];
 337  	 	 if ($type) {
 338  	 	 	 $obj->bindParam($name, $var, $type, $maxLen);
 339  	 	 }
 340  	 	 else {
 341  	 	 	 $obj->bindParam($name, $var);
 342  	 	 }
 343  	 }
 344  
 345  	function OffsetDate($dayFraction,$date=false)
 346  	 {
 347  	 	 return $this->_driver->OffsetDate($dayFraction,$date);
 348  	 }
 349  
 350  	function SelectDB($dbName)
 351  	 {
 352  	 	 return $this->_driver->SelectDB($dbName);
 353  	 }
 354  
 355  	function SQLDate($fmt, $col=false)
 356  	 {
 357  	 	 return $this->_driver->SQLDate($fmt, $col);
 358  	 }
 359  
 360  	function ErrorMsg()
 361  	 {
 362  	 	 if ($this->_errormsg !== false) {
 363  	 	 	 return $this->_errormsg;
 364  	 	 }
 365  	 	 if (!empty($this->_stmt)) {
 366  	 	 	 $arr = $this->_stmt->errorInfo();
 367  	 	 }
 368  	 	 else if (!empty($this->_connectionID)) {
 369  	 	 	 $arr = $this->_connectionID->errorInfo();
 370  	 	 }
 371  	 	 else {
 372  	 	 	 return 'No Connection Established';
 373  	 	 }
 374  
 375  	 	 if ($arr) {
 376  	 	 	 if (sizeof($arr)<2) {
 377  	 	 	 	 return '';
 378  	 	 	 }
 379  	 	 	 if ((integer)$arr[0]) {
 380  	 	 	 	 return $arr[2];
 381  	 	 	 }
 382  	 	 	 else {
 383  	 	 	 	 return '';
 384  	 	 	 }
 385  	 	 }
 386  	 	 else {
 387  	 	 	 return '-1';
 388  	 	 }
 389  	 }
 390  
 391  
 392  	function ErrorNo()
 393  	 {
 394  	 	 if ($this->_errorno !== false) {
 395  	 	 	 return $this->_errorno;
 396  	 	 }
 397  	 	 if (!empty($this->_stmt)) {
 398  	 	 	 $err = $this->_stmt->errorCode();
 399  	 	 }
 400  	 	 else if (!empty($this->_connectionID)) {
 401  	 	 	 $arr = $this->_connectionID->errorInfo();
 402  	 	 	 if (isset($arr[0])) {
 403  	 	 	 	 $err = $arr[0];
 404  	 	 	 }
 405  	 	 	 else {
 406  	 	 	 	 $err = -1;
 407  	 	 	 }
 408  	 	 } else {
 409  	 	 	 return 0;
 410  	 	 }
 411  
 412  	 	 if ($err == '00000') {
 413  	 	 	 return 0; // allows empty check
 414  	 	 }
 415  	 	 return $err;
 416  	 }
 417  
 418  	 /**
 419  	  * @param bool $auto_commit
 420  	  * @return void
 421  	  */
 422  	function SetAutoCommit($auto_commit)
 423  	 {
 424  	 	 if(method_exists($this->_driver, 'SetAutoCommit')) {
 425  	 	 	 $this->_driver->SetAutoCommit($auto_commit);
 426  	 	 }
 427  	 }
 428  
 429  	function SetTransactionMode($transaction_mode)
 430  	 {
 431  	 	 if(method_exists($this->_driver, 'SetTransactionMode')) {
 432  	 	 	 return $this->_driver->SetTransactionMode($transaction_mode);
 433  	 	 }
 434  
 435  	 	 return parent::SetTransactionMode($transaction_mode);
 436  	 }
 437  
 438  	function beginTrans()
 439  	 {
 440  	 	 if(method_exists($this->_driver, 'beginTrans')) {
 441  	 	 	 return $this->_driver->beginTrans();
 442  	 	 }
 443  
 444  	 	 if (!$this->hasTransactions) {
 445  	 	 	 return false;
 446  	 	 }
 447  	 	 if ($this->transOff) {
 448  	 	 	 return true;
 449  	 	 }
 450  	 	 $this->transCnt += 1;
 451  	 	 $this->_autocommit = false;
 452  	 	 $this->SetAutoCommit(false);
 453  
 454  	 	 return $this->_connectionID->beginTransaction();
 455  	 }
 456  
 457  	function commitTrans($ok=true)
 458  	 {
 459  
 460  	 	 if(method_exists($this->_driver, 'commitTrans')) {
 461  	 	 	 return $this->_driver->commitTrans($ok);
 462  	 	 }
 463  
 464  	 	 if (!$this->hasTransactions) {
 465  	 	 	 return false;
 466  	 	 }
 467  	 	 if ($this->transOff) {
 468  	 	 	 return true;
 469  	 	 }
 470  	 	 if (!$ok) {
 471  	 	 	 return $this->rollbackTrans();
 472  	 	 }
 473  	 	 if ($this->transCnt) {
 474  	 	 	 $this->transCnt -= 1;
 475  	 	 }
 476  	 	 $this->_autocommit = true;
 477  
 478  	 	 $ret = $this->_connectionID->commit();
 479  	 	 $this->SetAutoCommit(true);
 480  	 	 return $ret;
 481  	 }
 482  
 483  	function RollbackTrans()
 484  	 {
 485  	 	 if(method_exists($this->_driver, 'RollbackTrans')) {
 486  	 	 	 return $this->_driver->RollbackTrans();
 487  	 	 }
 488  
 489  	 	 if (!$this->hasTransactions) {
 490  	 	 	 return false;
 491  	 	 }
 492  	 	 if ($this->transOff) {
 493  	 	 	 return true;
 494  	 	 }
 495  	 	 if ($this->transCnt) {
 496  	 	 	 $this->transCnt -= 1;
 497  	 	 }
 498  	 	 $this->_autocommit = true;
 499  
 500  	 	 $ret = $this->_connectionID->rollback();
 501  	 	 $this->SetAutoCommit(true);
 502  	 	 return $ret;
 503  	 }
 504  
 505  	function Prepare($sql)
 506  	 {
 507  	 	 $this->_stmt = $this->_connectionID->prepare($sql);
 508  	 	 if ($this->_stmt) {
 509  	 	 	 return array($sql,$this->_stmt);
 510  	 	 }
 511  
 512  	 	 return false;
 513  	 }
 514  
 515  	function PrepareStmt($sql)
 516  	 {
 517  	 	 $stmt = $this->_connectionID->prepare($sql);
 518  	 	 if (!$stmt) {
 519  	 	 	 return false;
 520  	 	 }
 521  	 	 $obj = new ADOPDOStatement($stmt,$this);
 522  	 	 return $obj;
 523  	 }
 524  
 525  	public function createSequence($seqname='adodbseq',$startID=1)
 526  	 {
 527  	 	 if(method_exists($this->_driver, 'createSequence')) {
 528  	 	 	 return $this->_driver->createSequence($seqname, $startID);
 529  	 	 }
 530  
 531  	 	 return parent::CreateSequence($seqname, $startID);
 532  	 }
 533  
 534  	function DropSequence($seqname='adodbseq')
 535  	 {
 536  	 	 if(method_exists($this->_driver, 'DropSequence')) {
 537  	 	 	 return $this->_driver->DropSequence($seqname);
 538  	 	 }
 539  
 540  	 	 return parent::DropSequence($seqname);
 541  	 }
 542  
 543  	function GenID($seqname='adodbseq',$startID=1)
 544  	 {
 545  	 	 if(method_exists($this->_driver, 'GenID')) {
 546  	 	 	 return $this->_driver->GenID($seqname, $startID);
 547  	 	 }
 548  
 549  	 	 return parent::GenID($seqname, $startID);
 550  	 }
 551  
 552  
 553  	 /* returns queryID or false */
 554  	function _query($sql,$inputarr=false)
 555  	 {
 556  	 	 $ok = false;
 557  	 	 if (is_array($sql)) {
 558  	 	 	 $stmt = $sql[1];
 559  	 	 } else {
 560  	 	 	 $stmt = $this->_connectionID->prepare($sql);
 561  	 	 }
 562  	 	 
 563  	 	 if ($stmt) {
 564  	 	 	 if ($this->_driver instanceof ADODB_pdo) {
 565  	 	 	 	 $this->_driver->debug = $this->debug;
 566  	 	 	 }
 567  	 	 	 if ($inputarr) {
 568  	 	 	 	 $ok = $stmt->execute($inputarr);
 569  	 	 	 }
 570  	 	 	 else {
 571  	 	 	 	 $ok = $stmt->execute();
 572  	 	 	 }
 573  	 	 }
 574  
 575  
 576  	 	 $this->_errormsg = false;
 577  	 	 $this->_errorno = false;
 578  
 579  	 	 if ($ok) {
 580  	 	 	 $this->_stmt = $stmt;
 581  	 	 	 return $stmt;
 582  	 	 }
 583  
 584  	 	 if ($stmt) {
 585  
 586  	 	 	 $arr = $stmt->errorinfo();
 587  	 	 	 if ((integer)$arr[1]) {
 588  	 	 	 	 $this->_errormsg = $arr[2];
 589  	 	 	 	 $this->_errorno = $arr[1];
 590  	 	 	 }
 591  
 592  	 	 } else {
 593  	 	 	 $this->_errormsg = false;
 594  	 	 	 $this->_errorno = false;
 595  	 	 }
 596  	 	 return false;
 597  	 }
 598  
 599  	 // returns true or false
 600  	function _close()
 601  	 {
 602  	 	 $this->_stmt = false;
 603  	 	 return true;
 604  	 }
 605  
 606  	function _affectedrows()
 607  	 {
 608  	 	 if(method_exists($this->_driver, '_affectedrows'))
 609  	 	 	 return $this->_driver->_affectedrows();
 610  	 	 
 611  	 	 return ($this->_stmt) ? $this->_stmt->rowCount() : 0;
 612  	 }
 613  
 614  	function _insertid()
 615  	 {
 616  	 	 return ($this->_connectionID) ? $this->_connectionID->lastInsertId() : 0;
 617  	 }
 618  
 619  	 /**
 620  	  * Quotes a string to be sent to the database.
 621  	  *
 622  	  * If we have an active connection, delegates quoting to the underlying
 623  	  * PDO object PDO::quote(). Otherwise, replace "'" by the value of
 624  	  * $replaceQuote (same behavior as mysqli driver).
 625  	  *
 626  	  * @param string  $s           The string to quote
 627  	  * @param bool   $magic_quotes This param is not used since 5.21.0.
 628  	  *                             It remains for backwards compatibility.
 629  	  *
 630  	  * @return string Quoted string
 631  	  */
 632  	function qStr($s, $magic_quotes = false)
 633  	 {
 634  	 	 if ($this->_connectionID) {
 635  	 	 	 return $this->_connectionID->quote($s);
 636  	 	 }
 637  	 	 return "'" . str_replace("'", $this->replaceQuote, $s) . "'";
 638  	 }
 639  
 640  }
 641  
 642  class ADODB_pdo_base extends ADODB_pdo {
 643  
 644  	 var $sysDate = "'?'";
 645  	 var $sysTimeStamp = "'?'";
 646  
 647  
 648  	function _init($parentDriver)
 649  	 {
 650  	 	 $parentDriver->_bindInputArray = true;
 651  	 	 #$parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
 652  	 }
 653  
 654  	function ServerInfo()
 655  	 {
 656  	 	 return ADOConnection::ServerInfo();
 657  	 }
 658  
 659  	function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
 660  	 {
 661  	 	 $ret = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
 662  	 	 return $ret;
 663  	 }
 664  
 665  	function MetaTables($ttype=false,$showSchema=false,$mask=false)
 666  	 {
 667  	 	 return false;
 668  	 }
 669  
 670  	function MetaColumns($table,$normalize=true)
 671  	 {
 672  	 	 return false;
 673  	 }
 674  }
 675  
 676  class ADOPDOStatement {
 677  
 678  	 var $databaseType = "pdo";
 679  	 var $dataProvider = "pdo";
 680  	 var $_stmt;
 681  	 var $_connectionID;
 682  
 683  	function __construct($stmt,$connection)
 684  	 {
 685  	 	 $this->_stmt = $stmt;
 686  	 	 $this->_connectionID = $connection;
 687  	 }
 688  
 689  	function Execute($inputArr=false)
 690  	 {
 691  	 	 $savestmt = $this->_connectionID->_stmt;
 692  	 	 $rs = $this->_connectionID->Execute(array(false,$this->_stmt),$inputArr);
 693  	 	 $this->_connectionID->_stmt = $savestmt;
 694  	 	 return $rs;
 695  	 }
 696  
 697  	function InParameter(&$var,$name,$maxLen=4000,$type=false)
 698  	 {
 699  
 700  	 	 if ($type) {
 701  	 	 	 $this->_stmt->bindParam($name,$var,$type,$maxLen);
 702  	 	 }
 703  	 	 else {
 704  	 	 	 $this->_stmt->bindParam($name, $var);
 705  	 	 }
 706  	 }
 707  
 708  	function Affected_Rows()
 709  	 {
 710  	 	 return ($this->_stmt) ? $this->_stmt->rowCount() : 0;
 711  	 }
 712  
 713  	function ErrorMsg()
 714  	 {
 715  	 	 if ($this->_stmt) {
 716  	 	 	 $arr = $this->_stmt->errorInfo();
 717  	 	 }
 718  	 	 else {
 719  	 	 	 $arr = $this->_connectionID->errorInfo();
 720  	 	 }
 721  
 722  	 	 if (is_array($arr)) {
 723  	 	 	 if ((integer) $arr[0] && isset($arr[2])) {
 724  	 	 	 	 return $arr[2];
 725  	 	 	 }
 726  	 	 	 else {
 727  	 	 	 	 return '';
 728  	 	 	 }
 729  	 	 } else {
 730  	 	 	 return '-1';
 731  	 	 }
 732  	 }
 733  
 734  	function NumCols()
 735  	 {
 736  	 	 return ($this->_stmt) ? $this->_stmt->columnCount() : 0;
 737  	 }
 738  
 739  	function ErrorNo()
 740  	 {
 741  	 	 if ($this->_stmt) {
 742  	 	 	 return $this->_stmt->errorCode();
 743  	 	 }
 744  	 	 else {
 745  	 	 	 return $this->_connectionID->errorInfo();
 746  	 	 }
 747  	 }
 748  }
 749  
 750  /*--------------------------------------------------------------------------------------
 751  	 Class Name: Recordset
 752  --------------------------------------------------------------------------------------*/
 753  
 754  class ADORecordSet_pdo extends ADORecordSet {
 755  
 756  	 var $bind = false;
 757  	 var $databaseType = "pdo";
 758  	 var $dataProvider = "pdo";
 759  
 760  	function __construct($id,$mode=false)
 761  	 {
 762  	 	 if ($mode === false) {
 763  	 	 	 global $ADODB_FETCH_MODE;
 764  	 	 	 $mode = $ADODB_FETCH_MODE;
 765  	 	 }
 766  	 	 $this->adodbFetchMode = $mode;
 767  	 	 switch($mode) {
 768  	 	 case ADODB_FETCH_NUM: $mode = PDO::FETCH_NUM; break;
 769  	 	 case ADODB_FETCH_ASSOC:  $mode = PDO::FETCH_ASSOC; break;
 770  
 771  	 	 case ADODB_FETCH_BOTH:
 772  	 	 default: $mode = PDO::FETCH_BOTH; break;
 773  	 	 }
 774  	 	 $this->fetchMode = $mode;
 775  
 776  	 	 $this->_queryID = $id;
 777  	 	 parent::__construct($id);
 778  	 }
 779  
 780  
 781  	function Init()
 782  	 {
 783  	 	 if ($this->_inited) {
 784  	 	 	 return;
 785  	 	 }
 786  	 	 $this->_inited = true;
 787  	 	 if ($this->_queryID) {
 788  	 	 	 @$this->_initrs();
 789  	 	 }
 790  	 	 else {
 791  	 	 	 $this->_numOfRows = 0;
 792  	 	 	 $this->_numOfFields = 0;
 793  	 	 }
 794  	 	 if ($this->_numOfRows != 0 && $this->_currentRow == -1) {
 795  	 	 	 $this->_currentRow = 0;
 796  	 	 	 if ($this->EOF = ($this->_fetch() === false)) {
 797  	 	 	 	 $this->_numOfRows = 0; // _numOfRows could be -1
 798  	 	 	 }
 799  	 	 } else {
 800  	 	 	 $this->EOF = true;
 801  	 	 }
 802  	 }
 803  
 804  	function _initrs()
 805  	 {
 806  	 global $ADODB_COUNTRECS;
 807  
 808  	 	 $this->_numOfRows = ($ADODB_COUNTRECS) ? @$this->_queryID->rowCount() : -1;
 809  	 	 if (!$this->_numOfRows) {
 810  	 	 	 $this->_numOfRows = -1;
 811  	 	 }
 812  	 	 $this->_numOfFields = $this->_queryID->columnCount();
 813  	 }
 814  
 815  	 // returns the field object
 816  	function FetchField($fieldOffset = -1)
 817  	 {
 818  	 	 $off=$fieldOffset+1; // offsets begin at 1
 819  
 820  	 	 $o= new ADOFieldObject();
 821  	 	 $arr = @$this->_queryID->getColumnMeta($fieldOffset);
 822  	 	 if (!$arr) {
 823  	 	 	 $o->name = 'bad getColumnMeta()';
 824  	 	 	 $o->max_length = -1;
 825  	 	 	 $o->type = 'VARCHAR';
 826  	 	 	 $o->precision = 0;
 827  	 #	 	 $false = false;
 828  	 	 	 return $o;
 829  	 	 }
 830  	 	 //adodb_pr($arr);
 831  	 	 $o->name = $arr['name'];
 832  	 	 if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null") 
 833  	 	 {
 834  	 	     /*
 835  	 	     * If the database is SQL server, use the native built-ins
 836  	 	     */
 837  	 	     $o->type = $arr['sqlsrv:decl_type'];
 838  	 	 }
 839  	 	 elseif (isset($arr['native_type']) && $arr['native_type'] <> "null") 
 840  	 	 {
 841  	 	     $o->type = $arr['native_type'];
 842  	 	 }
 843  	 	 else 
 844  	 	 {
 845  	 	      $o->type = adodb_pdo_type($arr['pdo_type']);
 846  	 	 }
 847  	 	 
 848  	 	 $o->max_length = $arr['len'];
 849  	 	 $o->precision = $arr['precision'];
 850  
 851  	 	 switch(ADODB_ASSOC_CASE) {
 852  	 	 	 case ADODB_ASSOC_CASE_LOWER:
 853  	 	 	 	 $o->name = strtolower($o->name);
 854  	 	 	 	 break;
 855  	 	 	 case ADODB_ASSOC_CASE_UPPER:
 856  	 	 	 	 $o->name = strtoupper($o->name);
 857  	 	 	 	 break;
 858  	 	 }
 859  	 	 return $o;
 860  	 }
 861  
 862  	function _seek($row)
 863  	 {
 864  	 	 return false;
 865  	 }
 866  
 867  	function _fetch()
 868  	 {
 869  	 	 if (!$this->_queryID) {
 870  	 	 	 return false;
 871  	 	 }
 872  
 873  	 	 $this->fields = $this->_queryID->fetch($this->fetchMode);
 874  	 	 return !empty($this->fields);
 875  	 }
 876  
 877  	function _close()
 878  	 {
 879  	 	 $this->_queryID = false;
 880  	 }
 881  
 882  	function Fields($colname)
 883  	 {
 884  	 	 if ($this->adodbFetchMode != ADODB_FETCH_NUM) {
 885  	 	 	 return @$this->fields[$colname];
 886  	 	 }
 887  
 888  	 	 if (!$this->bind) {
 889  	 	 	 $this->bind = array();
 890  	 	 	 for ($i=0; $i < $this->_numOfFields; $i++) {
 891  	 	 	 	 $o = $this->FetchField($i);
 892  	 	 	 	 $this->bind[strtoupper($o->name)] = $i;
 893  	 	 	 }
 894  	 	 }
 895  	 	 return $this->fields[$this->bind[strtoupper($colname)]];
 896  	 }
 897  
 898  }
 899  
 900  class ADORecordSet_array_pdo extends ADORecordSet_array {}