5 V4.98 13 Feb 2008 (c) 2000-2008 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.
13 class ADODB_pdo_mysql
extends ADODB_pdo
{
14 var $metaTablesSQL = "SHOW TABLES";
15 var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
16 var $sysDate = 'CURDATE()';
17 var $sysTimeStamp = 'NOW()';
19 var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
20 var $_dropSeqSQL = "drop table %s";
24 function _init($parentDriver)
27 $parentDriver->hasTransactions
= false;
28 $parentDriver->_bindInputArray
= false;
29 $parentDriver->hasInsertID
= true;
30 $parentDriver->_connectionID
->setAttribute(PDO
::MYSQL_ATTR_USE_BUFFERED_QUERY
,true);
33 // dayFraction is a day in floating point
34 function OffsetDate($dayFraction,$date=false)
36 if (!$date) $date = $this->sysDate
;
38 $fraction = $dayFraction * 24 * 3600;
39 return $date . ' + INTERVAL ' . $fraction.' SECOND';
41 // return "from_unixtime(unix_timestamp($date)+$fraction)";
46 $arr['description'] = ADOConnection
::GetOne("select version()");
47 $arr['version'] = ADOConnection
::_findvers($arr['description']);
51 function &MetaTables($ttype=false,$showSchema=false,$mask=false)
53 $save = $this->metaTablesSQL
;
54 if ($showSchema && is_string($showSchema)) {
55 $this->metaTablesSQL
.= " from $showSchema";
59 $mask = $this->qstr($mask);
60 $this->metaTablesSQL
.= " like $mask";
62 $ret =& ADOConnection
::MetaTables($ttype,$showSchema);
64 $this->metaTablesSQL
= $save;
68 function SetTransactionMode( $transaction_mode )
70 $this->_transmode
= $transaction_mode;
71 if (empty($transaction_mode)) {
72 $this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
75 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
76 $this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
79 function &MetaColumns($table)
81 $this->_findschema($table,$schema);
83 $dbName = $this->database
;
84 $this->SelectDB($schema);
86 global $ADODB_FETCH_MODE;
87 $save = $ADODB_FETCH_MODE;
88 $ADODB_FETCH_MODE = ADODB_FETCH_NUM
;
90 if ($this->fetchMode
!== false) $savem = $this->SetFetchMode(false);
91 $rs = $this->Execute(sprintf($this->metaColumnsSQL
,$table));
94 $this->SelectDB($dbName);
97 if (isset($savem)) $this->SetFetchMode($savem);
98 $ADODB_FETCH_MODE = $save;
99 if (!is_object($rs)) {
106 $fld = new ADOFieldObject();
107 $fld->name
= $rs->fields
[0];
108 $type = $rs->fields
[1];
110 // split type into type(length):
112 if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
113 $fld->type
= $query_array[1];
114 $fld->max_length
= is_numeric($query_array[2]) ?
$query_array[2] : -1;
115 $fld->scale
= is_numeric($query_array[3]) ?
$query_array[3] : -1;
116 } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
117 $fld->type
= $query_array[1];
118 $fld->max_length
= is_numeric($query_array[2]) ?
$query_array[2] : -1;
119 } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
120 $fld->type
= $query_array[1];
121 $arr = explode(",",$query_array[2]);
123 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
124 $fld->max_length
= ($zlen > 0) ?
$zlen : 1;
127 $fld->max_length
= -1;
129 $fld->not_null
= ($rs->fields
[2] != 'YES');
130 $fld->primary_key
= ($rs->fields
[3] == 'PRI');
131 $fld->auto_increment
= (strpos($rs->fields
[5], 'auto_increment') !== false);
132 $fld->binary
= (strpos($type,'blob') !== false);
133 $fld->unsigned
= (strpos($type,'unsigned') !== false);
137 if ($d != '' && $d != 'NULL') {
138 $fld->has_default
= true;
139 $fld->default_value
= $d;
141 $fld->has_default
= false;
145 if ($save == ADODB_FETCH_NUM
) {
148 $retarr[strtoupper($fld->name
)] = $fld;
158 // parameters use PostgreSQL convention, not MySQL
159 function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
161 $offsetStr =($offset>=0) ?
"$offset," : '';
162 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
163 if ($nrows < 0) $nrows = '18446744073709551615';
166 $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
168 $rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);