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 401 and 402] [Versions 401 and 403]

   1  <?php
   2  /**
   3   * PDO sqlsrv 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   * @author Ned Andre
  21   */
  22  
  23  class ADODB_pdo_sqlsrv extends ADODB_pdo
  24  {
  25  	 var $hasTop = 'top';
  26  	 var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)';
  27  	 var $sysTimeStamp = 'GetDate()';
  28  	 var $arrayClass = 'ADORecordSet_array_pdo_sqlsrv';
  29  
  30  	function _init(ADODB_pdo $parentDriver)
  31  	 {
  32  	 	 $parentDriver->hasTransactions = true;
  33  	 	 $parentDriver->_bindInputArray = true;
  34  	 	 $parentDriver->hasInsertID = true;
  35  	 	 $parentDriver->fmtTimeStamp = "'Y-m-d H:i:s'";
  36  	 	 $parentDriver->fmtDate = "'Y-m-d'";
  37  	 }
  38  
  39  	function BeginTrans()
  40  	 {
  41  	 	 $returnval = parent::BeginTrans();
  42  	 	 return $returnval;
  43  	 }
  44  
  45  	function MetaColumns($table, $normalize = true)
  46  	 {
  47  	 	 return false;
  48  	 }
  49  
  50  	function MetaTables($ttype = false, $showSchema = false, $mask = false)
  51  	 {
  52  	 	 return false;
  53  	 }
  54  
  55  	function SelectLimit($sql, $nrows = -1, $offset = -1, $inputarr = false, $secs2cache = 0)
  56  	 {
  57  	 	 $ret = ADOConnection::SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
  58  	 	 return $ret;
  59  	 }
  60  
  61  	function ServerInfo()
  62  	 {
  63  	 	 return ADOConnection::ServerInfo();
  64  	 }
  65  }
  66  
  67  class ADORecordSet_pdo_sqlsrv extends ADORecordSet_pdo
  68  {
  69  
  70  	 public $databaseType = "pdo_sqlsrv";
  71  
  72  	 /**
  73  	  * returns the field object
  74  	  *
  75  	  * @param  int $fieldOffset Optional field offset
  76  	  *
  77  	  * @return object The ADOFieldObject describing the field
  78  	  */
  79  	public function fetchField($fieldOffset = 0)
  80  	 {
  81  
  82  	 	 // Default behavior allows passing in of -1 offset, which crashes the method
  83  	 	 if ($fieldOffset == -1) {
  84  	 	 	 $fieldOffset++;
  85  	 	 }
  86  
  87  	 	 $o = new ADOFieldObject();
  88  	 	 $arr = @$this->_queryID->getColumnMeta($fieldOffset);
  89  
  90  	 	 if (!$arr) {
  91  	 	 	 $o->name = 'bad getColumnMeta()';
  92  	 	 	 $o->max_length = -1;
  93  	 	 	 $o->type = 'VARCHAR';
  94  	 	 	 $o->precision = 0;
  95  	 	 	 return $o;
  96  	 	 }
  97  	 	 $o->name = $arr['name'];
  98  	 	 if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null") {
  99  	 	 	 // Use the SQL Server driver specific value
 100  	 	 	 $o->type = $arr['sqlsrv:decl_type'];
 101  	 	 } else {
 102  	 	 	 $o->type = adodb_pdo_type($arr['pdo_type']);
 103  	 	 }
 104  	 	 $o->max_length = $arr['len'];
 105  	 	 $o->precision = $arr['precision'];
 106  
 107  	 	 switch (ADODB_ASSOC_CASE) {
 108  	 	 	 case ADODB_ASSOC_CASE_LOWER:
 109  	 	 	 	 $o->name = strtolower($o->name);
 110  	 	 	 	 break;
 111  	 	 	 case ADODB_ASSOC_CASE_UPPER:
 112  	 	 	 	 $o->name = strtoupper($o->name);
 113  	 	 	 	 break;
 114  	 	 }
 115  
 116  	 	 return $o;
 117  	 }
 118  }
 119  
 120  class ADORecordSet_array_pdo_sqlsrv extends ADORecordSet_array_pdo
 121  {
 122  
 123  	 /**
 124  	  * returns the field object
 125  	  *
 126  	  * Note that this is a direct copy of the ADORecordSet_pdo_sqlsrv method
 127  	  *
 128  	  * @param  int $fieldOffset Optional field offset
 129  	  *
 130  	  * @return object The ADOfieldobject describing the field
 131  	  */
 132  	public function fetchField($fieldOffset = 0)
 133  	 {
 134  	 	 // Default behavior allows passing in of -1 offset, which crashes the method
 135  	 	 if ($fieldOffset == -1) {
 136  	 	 	 $fieldOffset++;
 137  	 	 }
 138  
 139  	 	 $o = new ADOFieldObject();
 140  	 	 $arr = @$this->_queryID->getColumnMeta($fieldOffset);
 141  
 142  	 	 if (!$arr) {
 143  	 	 	 $o->name = 'bad getColumnMeta()';
 144  	 	 	 $o->max_length = -1;
 145  	 	 	 $o->type = 'VARCHAR';
 146  	 	 	 $o->precision = 0;
 147  	 	 	 return $o;
 148  	 	 }
 149  	 	 $o->name = $arr['name'];
 150  	 	 if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null") {
 151  	 	 	 // Use the SQL Server driver specific value
 152  	 	 	 $o->type = $arr['sqlsrv:decl_type'];
 153  	 	 } else {
 154  	 	 	 $o->type = adodb_pdo_type($arr['pdo_type']);
 155  	 	 }
 156  	 	 $o->max_length = $arr['len'];
 157  	 	 $o->precision = $arr['precision'];
 158  
 159  	 	 switch (ADODB_ASSOC_CASE) {
 160  	 	 	 case ADODB_ASSOC_CASE_LOWER:
 161  	 	 	 	 $o->name = strtolower($o->name);
 162  	 	 	 	 break;
 163  	 	 	 case ADODB_ASSOC_CASE_UPPER:
 164  	 	 	 	 $o->name = strtoupper($o->name);
 165  	 	 	 	 break;
 166  	 	 }
 167  
 168  	 	 return $o;
 169  	 }
 170  	 
 171  	function SetTransactionMode( $transaction_mode )
 172  	 {
 173  	 	 $this->_transmode  = $transaction_mode;
 174  	 	 if (empty($transaction_mode)) {
 175  	 	 	 $this->_connectionID->query('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
 176  	 	 	 return;
 177  	 	 }
 178  	 	 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
 179  	 	 $this->_connectionID->query("SET TRANSACTION ".$transaction_mode);
 180  	 }
 181  }