00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 class ADODB_pdo_mysql extends ADODB_pdo {
00014 var $metaTablesSQL = "SHOW TABLES";
00015 var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
00016 var $_bindInputArray = false;
00017 var $sysDate = 'CURDATE()';
00018 var $sysTimeStamp = 'NOW()';
00019
00020 function _init($parentDriver)
00021 {
00022
00023 $parentDriver->hasTransactions = false;
00024 $parentDriver->_bindInputArray = true;
00025 $parentDriver->hasInsertID = true;
00026 $parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
00027 }
00028
00029 function ServerInfo()
00030 {
00031 $arr['description'] = ADOConnection::GetOne("select version()");
00032 $arr['version'] = ADOConnection::_findvers($arr['description']);
00033 return $arr;
00034 }
00035
00036 function &MetaTables($ttype=false,$showSchema=false,$mask=false)
00037 {
00038 $save = $this->metaTablesSQL;
00039 if ($showSchema && is_string($showSchema)) {
00040 $this->metaTablesSQL .= " from $showSchema";
00041 }
00042
00043 if ($mask) {
00044 $mask = $this->qstr($mask);
00045 $this->metaTablesSQL .= " like $mask";
00046 }
00047 $ret =& ADOConnection::MetaTables($ttype,$showSchema);
00048
00049 $this->metaTablesSQL = $save;
00050 return $ret;
00051 }
00052
00053 function SetTransactionMode( $transaction_mode )
00054 {
00055 $this->_transmode = $transaction_mode;
00056 if (empty($transaction_mode)) {
00057 $this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
00058 return;
00059 }
00060 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
00061 $this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
00062 }
00063
00064 function &MetaColumns($table)
00065 {
00066 $this->_findschema($table,$schema);
00067 if ($schema) {
00068 $dbName = $this->database;
00069 $this->SelectDB($schema);
00070 }
00071 global $ADODB_FETCH_MODE;
00072 $save = $ADODB_FETCH_MODE;
00073 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
00074
00075 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
00076 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
00077
00078 if ($schema) {
00079 $this->SelectDB($dbName);
00080 }
00081
00082 if (isset($savem)) $this->SetFetchMode($savem);
00083 $ADODB_FETCH_MODE = $save;
00084 if (!is_object($rs)) {
00085 $false = false;
00086 return $false;
00087 }
00088
00089 $retarr = array();
00090 while (!$rs->EOF){
00091 $fld = new ADOFieldObject();
00092 $fld->name = $rs->fields[0];
00093 $type = $rs->fields[1];
00094
00095
00096 $fld->scale = null;
00097 if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
00098 $fld->type = $query_array[1];
00099 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
00100 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
00101 } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
00102 $fld->type = $query_array[1];
00103 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
00104 } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
00105 $fld->type = $query_array[1];
00106 $arr = explode(",",$query_array[2]);
00107 $fld->enums = $arr;
00108 $zlen = max(array_map("strlen",$arr)) - 2;
00109 $fld->max_length = ($zlen > 0) ? $zlen : 1;
00110 } else {
00111 $fld->type = $type;
00112 $fld->max_length = -1;
00113 }
00114 $fld->not_null = ($rs->fields[2] != 'YES');
00115 $fld->primary_key = ($rs->fields[3] == 'PRI');
00116 $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
00117 $fld->binary = (strpos($type,'blob') !== false);
00118 $fld->unsigned = (strpos($type,'unsigned') !== false);
00119
00120 if (!$fld->binary) {
00121 $d = $rs->fields[4];
00122 if ($d != '' && $d != 'NULL') {
00123 $fld->has_default = true;
00124 $fld->default_value = $d;
00125 } else {
00126 $fld->has_default = false;
00127 }
00128 }
00129
00130 if ($save == ADODB_FETCH_NUM) {
00131 $retarr[] = $fld;
00132 } else {
00133 $retarr[strtoupper($fld->name)] = $fld;
00134 }
00135 $rs->MoveNext();
00136 }
00137
00138 $rs->Close();
00139 return $retarr;
00140 }
00141
00142
00143
00144 function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
00145 {
00146 $offsetStr =($offset>=0) ? "$offset," : '';
00147
00148 if ($nrows < 0) $nrows = '18446744073709551615';
00149
00150 if ($secs)
00151 $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
00152 else
00153 $rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
00154 return $rs;
00155 }
00156 }
00157 ?>