Documentation TYPO3 par Ameos

adodb-pdo_mysql.inc.php

00001 <?php
00002 
00003 
00004 /*
00005 V4.80 8 Mar 2006  (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
00006   Released under both BSD license and Lesser GPL library license. 
00007   Whenever there is any discrepancy between the two licenses, 
00008   the BSD license will take precedence.
00009   Set tabs to 8.
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 &MetaColumns($table) 
00054         {
00055                 $this->_findschema($table,$schema);
00056                 if ($schema) {
00057                         $dbName = $this->database;
00058                         $this->SelectDB($schema);
00059                 }
00060                 global $ADODB_FETCH_MODE;
00061                 $save = $ADODB_FETCH_MODE;
00062                 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
00063                 
00064                 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
00065                 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
00066                 
00067                 if ($schema) {
00068                         $this->SelectDB($dbName);
00069                 }
00070                 
00071                 if (isset($savem)) $this->SetFetchMode($savem);
00072                 $ADODB_FETCH_MODE = $save;
00073                 if (!is_object($rs)) {
00074                         $false = false;
00075                         return $false;
00076                 }
00077                         
00078                 $retarr = array();
00079                 while (!$rs->EOF){
00080                         $fld = new ADOFieldObject();
00081                         $fld->name = $rs->fields[0];
00082                         $type = $rs->fields[1];
00083                         
00084                         // split type into type(length):
00085                         $fld->scale = null;
00086                         if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
00087                                 $fld->type = $query_array[1];
00088                                 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
00089                                 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
00090                         } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
00091                                 $fld->type = $query_array[1];
00092                                 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
00093                         } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
00094                                 $fld->type = $query_array[1];
00095                                 $arr = explode(",",$query_array[2]);
00096                                 $fld->enums = $arr;
00097                                 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
00098                                 $fld->max_length = ($zlen > 0) ? $zlen : 1;
00099                         } else {
00100                                 $fld->type = $type;
00101                                 $fld->max_length = -1;
00102                         }
00103                         $fld->not_null = ($rs->fields[2] != 'YES');
00104                         $fld->primary_key = ($rs->fields[3] == 'PRI');
00105                         $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
00106                         $fld->binary = (strpos($type,'blob') !== false);
00107                         $fld->unsigned = (strpos($type,'unsigned') !== false);
00108                                 
00109                         if (!$fld->binary) {
00110                                 $d = $rs->fields[4];
00111                                 if ($d != '' && $d != 'NULL') {
00112                                         $fld->has_default = true;
00113                                         $fld->default_value = $d;
00114                                 } else {
00115                                         $fld->has_default = false;
00116                                 }
00117                         }
00118                         
00119                         if ($save == ADODB_FETCH_NUM) {
00120                                 $retarr[] = $fld;
00121                         } else {
00122                                 $retarr[strtoupper($fld->name)] = $fld;
00123                         }
00124                                 $rs->MoveNext();
00125                         }
00126                 
00127                         $rs->Close();
00128                         return $retarr; 
00129         }
00130                 
00131         
00132         // parameters use PostgreSQL convention, not MySQL
00133         function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
00134         {
00135                 $offsetStr =($offset>=0) ? "$offset," : '';
00136                 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
00137                 if ($nrows < 0) $nrows = '18446744073709551615'; 
00138                 
00139                 if ($secs)
00140                         $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
00141                 else
00142                         $rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
00143                 return $rs;
00144         }
00145 }
00146 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6