36 |
kaklik |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
/*
|
|
|
5 |
V4.80 8 Mar 2006 (c) 2000-2006 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 |
|
|
|
13 |
class 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 = true;
|
|
|
25 |
$parentDriver->hasInsertID = true;
|
|
|
26 |
$parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
function ServerInfo()
|
|
|
30 |
{
|
|
|
31 |
$arr['description'] = ADOConnection::GetOne("select version()");
|
|
|
32 |
$arr['version'] = ADOConnection::_findvers($arr['description']);
|
|
|
33 |
return $arr;
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
function &MetaTables($ttype=false,$showSchema=false,$mask=false)
|
|
|
37 |
{
|
|
|
38 |
$save = $this->metaTablesSQL;
|
|
|
39 |
if ($showSchema && is_string($showSchema)) {
|
|
|
40 |
$this->metaTablesSQL .= " from $showSchema";
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
if ($mask) {
|
|
|
44 |
$mask = $this->qstr($mask);
|
|
|
45 |
$this->metaTablesSQL .= " like $mask";
|
|
|
46 |
}
|
|
|
47 |
$ret =& ADOConnection::MetaTables($ttype,$showSchema);
|
|
|
48 |
|
|
|
49 |
$this->metaTablesSQL = $save;
|
|
|
50 |
return $ret;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
function &MetaColumns($table)
|
|
|
54 |
{
|
|
|
55 |
$this->_findschema($table,$schema);
|
|
|
56 |
if ($schema) {
|
|
|
57 |
$dbName = $this->database;
|
|
|
58 |
$this->SelectDB($schema);
|
|
|
59 |
}
|
|
|
60 |
global $ADODB_FETCH_MODE;
|
|
|
61 |
$save = $ADODB_FETCH_MODE;
|
|
|
62 |
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
|
|
63 |
|
|
|
64 |
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
|
|
|
65 |
$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
|
|
|
66 |
|
|
|
67 |
if ($schema) {
|
|
|
68 |
$this->SelectDB($dbName);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
if (isset($savem)) $this->SetFetchMode($savem);
|
|
|
72 |
$ADODB_FETCH_MODE = $save;
|
|
|
73 |
if (!is_object($rs)) {
|
|
|
74 |
$false = false;
|
|
|
75 |
return $false;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
$retarr = array();
|
|
|
79 |
while (!$rs->EOF){
|
|
|
80 |
$fld = new ADOFieldObject();
|
|
|
81 |
$fld->name = $rs->fields[0];
|
|
|
82 |
$type = $rs->fields[1];
|
|
|
83 |
|
|
|
84 |
// split type into type(length):
|
|
|
85 |
$fld->scale = null;
|
|
|
86 |
if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
|
|
|
87 |
$fld->type = $query_array[1];
|
|
|
88 |
$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
|
|
|
89 |
$fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
|
|
|
90 |
} elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
|
|
|
91 |
$fld->type = $query_array[1];
|
|
|
92 |
$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
|
|
|
93 |
} elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
|
|
|
94 |
$fld->type = $query_array[1];
|
|
|
95 |
$arr = explode(",",$query_array[2]);
|
|
|
96 |
$fld->enums = $arr;
|
|
|
97 |
$zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
|
|
|
98 |
$fld->max_length = ($zlen > 0) ? $zlen : 1;
|
|
|
99 |
} else {
|
|
|
100 |
$fld->type = $type;
|
|
|
101 |
$fld->max_length = -1;
|
|
|
102 |
}
|
|
|
103 |
$fld->not_null = ($rs->fields[2] != 'YES');
|
|
|
104 |
$fld->primary_key = ($rs->fields[3] == 'PRI');
|
|
|
105 |
$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
|
|
|
106 |
$fld->binary = (strpos($type,'blob') !== false);
|
|
|
107 |
$fld->unsigned = (strpos($type,'unsigned') !== false);
|
|
|
108 |
|
|
|
109 |
if (!$fld->binary) {
|
|
|
110 |
$d = $rs->fields[4];
|
|
|
111 |
if ($d != '' && $d != 'NULL') {
|
|
|
112 |
$fld->has_default = true;
|
|
|
113 |
$fld->default_value = $d;
|
|
|
114 |
} else {
|
|
|
115 |
$fld->has_default = false;
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
if ($save == ADODB_FETCH_NUM) {
|
|
|
120 |
$retarr[] = $fld;
|
|
|
121 |
} else {
|
|
|
122 |
$retarr[strtoupper($fld->name)] = $fld;
|
|
|
123 |
}
|
|
|
124 |
$rs->MoveNext();
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
$rs->Close();
|
|
|
128 |
return $retarr;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
// parameters use PostgreSQL convention, not MySQL
|
|
|
133 |
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
|
|
|
134 |
{
|
|
|
135 |
$offsetStr =($offset>=0) ? "$offset," : '';
|
|
|
136 |
// jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
|
|
|
137 |
if ($nrows < 0) $nrows = '18446744073709551615';
|
|
|
138 |
|
|
|
139 |
if ($secs)
|
|
|
140 |
$rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
|
|
|
141 |
else
|
|
|
142 |
$rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
|
|
|
143 |
return $rs;
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
?>
|