5 V4.94 23 Jan 2007 (c) 2000-2007 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()';
20 function _init($parentDriver)
23 $parentDriver->hasTransactions
= false;
24 $parentDriver->_bindInputArray
= false;
25 $parentDriver->hasInsertID
= true;
26 $parentDriver->_connectionID
->setAttribute(PDO
::MYSQL_ATTR_USE_BUFFERED_QUERY
,true);
29 // dayFraction is a day in floating point
30 function OffsetDate($dayFraction,$date=false)
32 if (!$date) $date = $this->sysDate
;
34 $fraction = $dayFraction * 24 * 3600;
35 return $date . ' + INTERVAL ' . $fraction.' SECOND';
37 // return "from_unixtime(unix_timestamp($date)+$fraction)";
42 $arr['description'] = ADOConnection
::GetOne("select version()");
43 $arr['version'] = ADOConnection
::_findvers($arr['description']);
47 function &MetaTables($ttype=false,$showSchema=false,$mask=false)
49 $save = $this->metaTablesSQL
;
50 if ($showSchema && is_string($showSchema)) {
51 $this->metaTablesSQL
.= " from $showSchema";
55 $mask = $this->qstr($mask);
56 $this->metaTablesSQL
.= " like $mask";
58 $ret =& ADOConnection
::MetaTables($ttype,$showSchema);
60 $this->metaTablesSQL
= $save;
64 function SetTransactionMode( $transaction_mode )
66 $this->_transmode
= $transaction_mode;
67 if (empty($transaction_mode)) {
68 $this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
71 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
72 $this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
75 function &MetaColumns($table)
77 $this->_findschema($table,$schema);
79 $dbName = $this->database
;
80 $this->SelectDB($schema);
82 global $ADODB_FETCH_MODE;
83 $save = $ADODB_FETCH_MODE;
84 $ADODB_FETCH_MODE = ADODB_FETCH_NUM
;
86 if ($this->fetchMode
!== false) $savem = $this->SetFetchMode(false);
87 $rs = $this->Execute(sprintf($this->metaColumnsSQL
,$table));
90 $this->SelectDB($dbName);
93 if (isset($savem)) $this->SetFetchMode($savem);
94 $ADODB_FETCH_MODE = $save;
95 if (!is_object($rs)) {
102 $fld = new ADOFieldObject();
103 $fld->name
= $rs->fields
[0];
104 $type = $rs->fields
[1];
106 // split type into type(length):
108 if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
109 $fld->type
= $query_array[1];
110 $fld->max_length
= is_numeric($query_array[2]) ?
$query_array[2] : -1;
111 $fld->scale
= is_numeric($query_array[3]) ?
$query_array[3] : -1;
112 } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
113 $fld->type
= $query_array[1];
114 $fld->max_length
= is_numeric($query_array[2]) ?
$query_array[2] : -1;
115 } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
116 $fld->type
= $query_array[1];
117 $arr = explode(",",$query_array[2]);
119 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
120 $fld->max_length
= ($zlen > 0) ?
$zlen : 1;
123 $fld->max_length
= -1;
125 $fld->not_null
= ($rs->fields
[2] != 'YES');
126 $fld->primary_key
= ($rs->fields
[3] == 'PRI');
127 $fld->auto_increment
= (strpos($rs->fields
[5], 'auto_increment') !== false);
128 $fld->binary
= (strpos($type,'blob') !== false);
129 $fld->unsigned
= (strpos($type,'unsigned') !== false);
133 if ($d != '' && $d != 'NULL') {
134 $fld->has_default
= true;
135 $fld->default_value
= $d;
137 $fld->has_default
= false;
141 if ($save == ADODB_FETCH_NUM
) {
144 $retarr[strtoupper($fld->name
)] = $fld;
154 // parameters use PostgreSQL convention, not MySQL
155 function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
157 $offsetStr =($offset>=0) ?
"$offset," : '';
158 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
159 if ($nrows < 0) $nrows = '18446744073709551615';
162 $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
164 $rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);