4 * Copyright 2005 $ThePhpWikiProgrammingTeam
6 * This file is part of PhpWiki.
8 * PhpWiki is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * PhpWiki is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * @author: Reini Urban
26 require_once 'lib/WikiDB/backend/PDO.php';
28 class WikiDB_backend_PDO_mysql
29 extends WikiDB_backend_PDO
31 function WikiDB_backend_PDO_mysql($dbparams)
34 $this->WikiDB_backend_PDO($dbparams);
36 if (!empty($this->_serverinfo['version'])) {
37 $arr = explode('.', $this->_serverinfo['version']);
38 $this->_serverinfo['version'] = (string)(($arr[0] * 100) + $arr[1]) . "." . (integer)$arr[2];
40 if ($this->_serverinfo['version'] < 323.0) {
41 // Older MySQL's don't have CASE WHEN ... END
42 $this->_expressions['maxmajor'] = "MAX(IF(minor_edit=0,version,0))";
43 $this->_expressions['maxminor'] = "MAX(IF(minor_edit<>0,version,0))";
46 if ($this->_serverinfo['version'] > 401.0) {
47 mysql_query("SET NAMES 'UTF-8'");
51 function backendType()
57 * Kill timed out processes. ( so far only called on about every 50-th save. )
61 if (empty($this->_dbparams['timeout'])) return;
62 $sth = $this->_dbh->prepare("SHOW processlist");
64 while ($row = $sth->fetch(PDO_FETCH_ASSOC)) {
65 if ($row["db"] == $this->_dsn['database']
66 and $row["User"] == $this->_dsn['username']
67 and $row["Time"] > $this->_dbparams['timeout']
68 and $row["Command"] == "Sleep"
70 $process_id = $row["Id"];
71 $this->query("KILL $process_id");
82 foreach ($this->_table_names as $table) {
83 $this->query("OPTIMIZE TABLE $table");
88 function listOfTables()
90 $sth = $this->_dbh->prepare("SHOW TABLES");
93 while ($row = $sth->fetch(PDO_FETCH_NUM)) {
99 function listOfFields($database, $table)
101 $old_db = $this->database();
102 if ($database != $old_db) {
104 $dsn = preg_replace("/dbname=\w+;/", "dbname=" . $database, $this->_dsn);
105 $dsn = preg_replace("/database=\w+;/", "database=" . $database, $dsn);
106 $conn = new PDO($dsn,
107 DBADMIN_USER ? DBADMIN_USER : $this->_parsedDSN['username'],
108 DBADMIN_PASSWD ? DBADMIN_PASSWD : $this->_parsedDSN['password']);
109 } catch (PDOException $e) {
110 echo "<br>\nDB Connection failed: " . $e->getMessage();
111 echo "<br>\nDSN: '", $this->_dsn, "'";
112 echo "<br>\n_parsedDSN: '", print_r($this->_parsedDSN), "'";
118 $sth = $conn->prepare("SHOW COLUMNS FROM $table");
120 $field_list = array();
121 while ($row = $sth->fetch(PDO_FETCH_NUM)) {
122 $field_list[] = $row[0];
124 if ($database != $old_db) {
131 * offset specific syntax within mysql
132 * convert from,count to SQL "LIMIT $offset, $count"
134 function _limit_sql($limit = false)
137 list($offset, $count) = $this->limit($limit);
139 // pgsql needs "LIMIT $count OFFSET $from"
140 $limit = " LIMIT $offset, $count";
142 $limit = " LIMIT $count";
154 // c-hanging-comment-ender-p: nil
155 // indent-tabs-mode: nil