Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

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