1<?php 2 3 4/* 5V4.65 22 July 2005 (c) 2000-2005 John Lim (jlim@natsoft.com.my). All rights reserved. 6 Released under both BSD license and Lesser GPL library license. 7 Whenever there is any discrepancy between the two licenses, 8 the BSD license will take precedence. 9 Set tabs to 8. 10 11*/ 12 13class ADODB_pdo_mysql extends ADODB_pdo { 14 var $metaTablesSQL = "SHOW TABLES"; 15 var $metaColumnsSQL = "SHOW COLUMNS FROM %s"; 16 var $_bindInputArray = false; 17 var $sysDate = 'CURDATE()'; 18 var $sysTimeStamp = 'NOW()'; 19 20 function _init($parentDriver) 21 { 22 23 $parentDriver->hasTransactions = false; 24 $parentDriver->_bindInputArray = false; 25 $parentDriver->_connectionID->setAttribute(PDO_MYSQL_ATTR_USE_BUFFERED_QUERY,true); 26 } 27 28 function ServerInfo() 29 { 30 $arr['description'] = ADOConnection::GetOne("select version()"); 31 $arr['version'] = ADOConnection::_findvers($arr['description']); 32 return $arr; 33 } 34 35 function &MetaTables($ttype=false,$showSchema=false,$mask=false) 36 { 37 $save = $this->metaTablesSQL; 38 if ($showSchema && is_string($showSchema)) { 39 $this->metaTablesSQL .= " from $showSchema"; 40 } 41 42 if ($mask) { 43 $mask = $this->qstr($mask); 44 $this->metaTablesSQL .= " like $mask"; 45 } 46 $ret =& ADOConnection::MetaTables($ttype,$showSchema); 47 48 $this->metaTablesSQL = $save; 49 return $ret; 50 } 51 52 function &MetaColumns($table) 53 { 54 $this->_findschema($table,$schema); 55 if ($schema) { 56 $dbName = $this->database; 57 $this->SelectDB($schema); 58 } 59 global $ADODB_FETCH_MODE; 60 $save = $ADODB_FETCH_MODE; 61 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 62 63 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); 64 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table)); 65 66 if ($schema) { 67 $this->SelectDB($dbName); 68 } 69 70 if (isset($savem)) $this->SetFetchMode($savem); 71 $ADODB_FETCH_MODE = $save; 72 if (!is_object($rs)) { 73 $false = false; 74 return $false; 75 } 76 77 $retarr = array(); 78 while (!$rs->EOF){ 79 $fld = new ADOFieldObject(); 80 $fld->name = $rs->fields[0]; 81 $type = $rs->fields[1]; 82 83 // split type into type(length): 84 $fld->scale = null; 85 if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) { 86 $fld->type = $query_array[1]; 87 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1; 88 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1; 89 } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) { 90 $fld->type = $query_array[1]; 91 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1; 92 } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) { 93 $fld->type = $query_array[1]; 94 $arr = explode(",",$query_array[2]); 95 $fld->enums = $arr; 96 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6 97 $fld->max_length = ($zlen > 0) ? $zlen : 1; 98 } else { 99 $fld->type = $type; 100 $fld->max_length = -1; 101 } 102 $fld->not_null = ($rs->fields[2] != 'YES'); 103 $fld->primary_key = ($rs->fields[3] == 'PRI'); 104 $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false); 105 $fld->binary = (strpos($type,'blob') !== false); 106 $fld->unsigned = (strpos($type,'unsigned') !== false); 107 108 if (!$fld->binary) { 109 $d = $rs->fields[4]; 110 if ($d != '' && $d != 'NULL') { 111 $fld->has_default = true; 112 $fld->default_value = $d; 113 } else { 114 $fld->has_default = false; 115 } 116 } 117 118 if ($save == ADODB_FETCH_NUM) { 119 $retarr[] = $fld; 120 } else { 121 $retarr[strtoupper($fld->name)] = $fld; 122 } 123 $rs->MoveNext(); 124 } 125 126 $rs->Close(); 127 return $retarr; 128 } 129 130 131 // parameters use PostgreSQL convention, not MySQL 132 function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0) 133 { 134 $offsetStr =($offset>=0) ? "$offset," : ''; 135 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220 136 if ($nrows < 0) $nrows = '18446744073709551615'; 137 138 if ($secs) 139 $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr); 140 else 141 $rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr); 142 return $rs; 143 } 144} 145?>