ona  18.1.1
About: OpenNetAdmin provides a database managed inventory of your IP network (with Web and CLI interface).
  Fossies Dox: ona-18.1.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

adodb-pdo_mysql.inc.php
Go to the documentation of this file.
1 <?php
2 /*
3 @version v5.20.9 21-Dec-2016
4 @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
5 @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
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 
15  var $metaTablesSQL = "SELECT
16  TABLE_NAME,
17  CASE WHEN TABLE_TYPE = 'VIEW' THEN 'V' ELSE 'T' END
18  FROM INFORMATION_SCHEMA.TABLES
19  WHERE TABLE_SCHEMA=";
20  var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
21  var $sysDate = 'CURDATE()';
22  var $sysTimeStamp = 'NOW()';
23  var $hasGenID = true;
24  var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
25  var $_dropSeqSQL = "drop table %s";
26  var $fmtTimeStamp = "'Y-m-d, H:i:s'";
27  var $nameQuote = '`';
28 
29  function _init($parentDriver)
30  {
31  $parentDriver->hasTransactions = false;
32  #$parentDriver->_bindInputArray = false;
33  $parentDriver->hasInsertID = true;
34  $parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
35  }
36 
37  // dayFraction is a day in floating point
38  function OffsetDate($dayFraction, $date=false)
39  {
40  if (!$date) {
41  $date = $this->sysDate;
42  }
43 
44  $fraction = $dayFraction * 24 * 3600;
45  return $date . ' + INTERVAL ' . $fraction . ' SECOND';
46 // return "from_unixtime(unix_timestamp($date)+$fraction)";
47  }
48 
49  function Concat()
50  {
51  $s = '';
52  $arr = func_get_args();
53 
54  // suggestion by andrew005#mnogo.ru
55  $s = implode(',', $arr);
56  if (strlen($s) > 0) {
57  return "CONCAT($s)";
58  }
59  return '';
60  }
61 
62  function ServerInfo()
63  {
64  $arr['description'] = ADOConnection::GetOne('select version()');
65  $arr['version'] = ADOConnection::_findvers($arr['description']);
66  return $arr;
67  }
68 
69  function MetaTables($ttype=false, $showSchema=false, $mask=false)
70  {
71  $save = $this->metaTablesSQL;
72  if ($showSchema && is_string($showSchema)) {
73  $this->metaTablesSQL .= $this->qstr($showSchema);
74  } else {
75  $this->metaTablesSQL .= 'schema()';
76  }
77 
78  if ($mask) {
79  $mask = $this->qstr($mask);
80  $this->metaTablesSQL .= " like $mask";
81  }
82  $ret = ADOConnection::MetaTables($ttype, $showSchema);
83 
84  $this->metaTablesSQL = $save;
85  return $ret;
86  }
87 
88  function SetTransactionMode($transaction_mode)
89  {
90  $this->_transmode = $transaction_mode;
91  if (empty($transaction_mode)) {
92  $this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
93  return;
94  }
95  if (!stristr($transaction_mode, 'isolation')) {
96  $transaction_mode = 'ISOLATION LEVEL ' . $transaction_mode;
97  }
98  $this->Execute('SET SESSION TRANSACTION ' . $transaction_mode);
99  }
100 
101  function MetaColumns($table, $normalize=true)
102  {
103  $this->_findschema($table, $schema);
104  if ($schema) {
105  $dbName = $this->database;
106  $this->SelectDB($schema);
107  }
108  global $ADODB_FETCH_MODE;
109  $save = $ADODB_FETCH_MODE;
110  $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
111 
112  if ($this->fetchMode !== false) {
113  $savem = $this->SetFetchMode(false);
114  }
115  $rs = $this->Execute(sprintf($this->metaColumnsSQL, $table));
116 
117  if ($schema) {
118  $this->SelectDB($dbName);
119  }
120 
121  if (isset($savem)) {
122  $this->SetFetchMode($savem);
123  }
124  $ADODB_FETCH_MODE = $save;
125  if (!is_object($rs)) {
126  $false = false;
127  return $false;
128  }
129 
130  $retarr = array();
131  while (!$rs->EOF){
132  $fld = new ADOFieldObject();
133  $fld->name = $rs->fields[0];
134  $type = $rs->fields[1];
135 
136  // split type into type(length):
137  $fld->scale = null;
138  if (preg_match('/^(.+)\((\d+),(\d+)/', $type, $query_array)) {
139  $fld->type = $query_array[1];
140  $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
141  $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
142  } elseif (preg_match('/^(.+)\((\d+)/', $type, $query_array)) {
143  $fld->type = $query_array[1];
144  $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
145  } elseif (preg_match('/^(enum)\((.*)\)$/i', $type, $query_array)) {
146  $fld->type = $query_array[1];
147  $arr = explode(',', $query_array[2]);
148  $fld->enums = $arr;
149  $zlen = max(array_map('strlen', $arr)) - 2; // PHP >= 4.0.6
150  $fld->max_length = ($zlen > 0) ? $zlen : 1;
151  } else {
152  $fld->type = $type;
153  $fld->max_length = -1;
154  }
155  $fld->not_null = ($rs->fields[2] != 'YES');
156  $fld->primary_key = ($rs->fields[3] == 'PRI');
157  $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
158  $fld->binary = (strpos($type, 'blob') !== false);
159  $fld->unsigned = (strpos($type, 'unsigned') !== false);
160 
161  if (!$fld->binary) {
162  $d = $rs->fields[4];
163  if ($d != '' && $d != 'NULL') {
164  $fld->has_default = true;
165  $fld->default_value = $d;
166  } else {
167  $fld->has_default = false;
168  }
169  }
170 
171  if ($save == ADODB_FETCH_NUM) {
172  $retarr[] = $fld;
173  } else {
174  $retarr[strtoupper($fld->name)] = $fld;
175  }
176  $rs->MoveNext();
177  }
178 
179  $rs->Close();
180  return $retarr;
181  }
182 
183  // returns true or false
184  function SelectDB($dbName)
185  {
186  $this->database = $dbName;
187  $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
188  $try = $this->Execute('use ' . $dbName);
189  return ($try !== false);
190  }
191 
192  // parameters use PostgreSQL convention, not MySQL
193  function SelectLimit($sql, $nrows=-1, $offset=-1, $inputarr=false, $secs=0)
194  {
195  $offsetStr =($offset>=0) ? "$offset," : '';
196  // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
197  if ($nrows < 0) {
198  $nrows = '18446744073709551615';
199  }
200 
201  if ($secs) {
202  $rs = $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows", $inputarr);
203  } else {
204  $rs = $this->Execute($sql . " LIMIT $offsetStr$nrows", $inputarr);
205  }
206  return $rs;
207  }
208 
209  function SQLDate($fmt, $col=false)
210  {
211  if (!$col) {
212  $col = $this->sysTimeStamp;
213  }
214  $s = 'DATE_FORMAT(' . $col . ",'";
215  $concat = false;
216  $len = strlen($fmt);
217  for ($i=0; $i < $len; $i++) {
218  $ch = $fmt[$i];
219  switch($ch) {
220 
221  default:
222  if ($ch == '\\') {
223  $i++;
224  $ch = substr($fmt, $i, 1);
225  }
226  // FALL THROUGH
227  case '-':
228  case '/':
229  $s .= $ch;
230  break;
231 
232  case 'Y':
233  case 'y':
234  $s .= '%Y';
235  break;
236 
237  case 'M':
238  $s .= '%b';
239  break;
240 
241  case 'm':
242  $s .= '%m';
243  break;
244 
245  case 'D':
246  case 'd':
247  $s .= '%d';
248  break;
249 
250  case 'Q':
251  case 'q':
252  $s .= "'),Quarter($col)";
253 
254  if ($len > $i+1) {
255  $s .= ",DATE_FORMAT($col,'";
256  } else {
257  $s .= ",('";
258  }
259  $concat = true;
260  break;
261 
262  case 'H':
263  $s .= '%H';
264  break;
265 
266  case 'h':
267  $s .= '%I';
268  break;
269 
270  case 'i':
271  $s .= '%i';
272  break;
273 
274  case 's':
275  $s .= '%s';
276  break;
277 
278  case 'a':
279  case 'A':
280  $s .= '%p';
281  break;
282 
283  case 'w':
284  $s .= '%w';
285  break;
286 
287  case 'W':
288  $s .= '%U';
289  break;
290 
291  case 'l':
292  $s .= '%W';
293  break;
294  }
295  }
296  $s .= "')";
297  if ($concat) {
298  $s = "CONCAT($s)";
299  }
300  return $s;
301  }
302 }
ADODB_pdo_mysql\MetaTables
MetaTables($ttype=false, $showSchema=false, $mask=false)
Definition: adodb-pdo_mysql.inc.php:69
ADODB_pdo_mysql\$nameQuote
$nameQuote
Definition: adodb-pdo_mysql.inc.php:27
ADODB_pdo_mysql\$fmtTimeStamp
$fmtTimeStamp
Definition: adodb-pdo_mysql.inc.php:26
ADODB_pdo_mysql\$_dropSeqSQL
$_dropSeqSQL
Definition: adodb-pdo_mysql.inc.php:25
$rs
if(isset($_REQUEST['nrows'])) else $rs
Definition: server.php:94
ADODB_pdo_mysql\SelectLimit
SelectLimit($sql, $nrows=-1, $offset=-1, $inputarr=false, $secs=0)
Definition: adodb-pdo_mysql.inc.php:193
$sql
$sql
Definition: server.php:84
ADODB_pdo_mysql\ServerInfo
ServerInfo()
Definition: adodb-pdo_mysql.inc.php:62
$ADODB_FETCH_MODE
$ADODB_FETCH_MODE
Definition: functions_db.inc.php:70
ADODB_pdo_mysql\SelectDB
SelectDB($dbName)
Definition: adodb-pdo_mysql.inc.php:184
ADODB_pdo_mysql\$hasGenID
$hasGenID
Definition: adodb-pdo_mysql.inc.php:23
ADODB_pdo_mysql\Concat
Concat()
Definition: adodb-pdo_mysql.inc.php:49
ADODB_pdo_mysql\_init
_init($parentDriver)
Definition: adodb-pdo_mysql.inc.php:29
ADODB_pdo_mysql\$sysDate
$sysDate
Definition: adodb-pdo_mysql.inc.php:21
ADODB_pdo_mysql\$metaTablesSQL
$metaTablesSQL
Definition: adodb-pdo_mysql.inc.php:15
ADODB_pdo_mysql\$sysTimeStamp
$sysTimeStamp
Definition: adodb-pdo_mysql.inc.php:22
$database
$database
Definition: collate-convert.php:18
$type
$type
Definition: dcm.php:17
ADODB_pdo\qstr
qstr($s, $magic_quotes=false)
Definition: adodb-pdo.inc.php:531
ADODB_pdo_mysql\SQLDate
SQLDate($fmt, $col=false)
Definition: adodb-pdo_mysql.inc.php:209
ADODB_pdo_mysql\SetTransactionMode
SetTransactionMode($transaction_mode)
Definition: adodb-pdo_mysql.inc.php:88
ADODB_pdo
Definition: adodb-pdo.inc.php:68
ADODB_pdo_mysql\$_genIDSQL
$_genIDSQL
Definition: adodb-pdo_mysql.inc.php:24
ADODB_pdo_mysql\OffsetDate
OffsetDate($dayFraction, $date=false)
Definition: adodb-pdo_mysql.inc.php:38
ADODB_pdo_mysql\MetaColumns
MetaColumns($table, $normalize=true)
Definition: adodb-pdo_mysql.inc.php:101
ADODB_pdo_mysql\$metaColumnsSQL
$metaColumnsSQL
Definition: adodb-pdo_mysql.inc.php:20
ADODB_pdo_mysql
Definition: adodb-pdo_mysql.inc.php:13