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 __construct($dbparams)
33 parent::__construct($dbparams);
35 if (!empty($this->_serverinfo['version'])) {
36 $arr = explode('.', $this->_serverinfo['version']);
37 $this->_serverinfo['version'] = (string)(($arr[0] * 100) + $arr[1]) . "." . (integer)$arr[2];
39 if ($this->_serverinfo['version'] < 323.0) {
40 // Older MySQL's don't have CASE WHEN ... END
41 $this->_expressions['maxmajor'] = "MAX(IF(minor_edit=0,version,0))";
42 $this->_expressions['maxminor'] = "MAX(IF(minor_edit<>0,version,0))";
45 if ($this->_serverinfo['version'] > 401.0) {
46 mysql_query("SET NAMES 'UTF-8'");
50 function backendType()
56 * Kill timed out processes. ( so far only called on about every 50-th save. )
60 if (empty($this->_dbparams['timeout'])) return;
61 $sth = $this->_dbh->prepare("SHOW processlist");
63 while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
64 if ($row["db"] == $this->_dsn['database']
65 and $row["User"] == $this->_dsn['username']
66 and $row["Time"] > $this->_dbparams['timeout']
67 and $row["Command"] == "Sleep"
69 $process_id = $row["Id"];
70 $this->query("KILL $process_id");
81 foreach ($this->_table_names as $table) {
82 $this->query("OPTIMIZE TABLE $table");
87 function listOfTables()
89 $sth = $this->_dbh->prepare("SHOW TABLES");
92 while ($row = $sth->fetch(PDO::FETCH_NUM)) {
98 function listOfFields($database, $table)
100 $old_db = $this->database();
101 if ($database != $old_db) {
103 $dsn = preg_replace("/dbname=\w+;/", "dbname=" . $database, $this->_dsn);
104 $dsn = preg_replace("/database=\w+;/", "database=" . $database, $dsn);
105 $conn = new PDO($dsn,
106 DBADMIN_USER ? DBADMIN_USER : $this->_parsedDSN['username'],
107 DBADMIN_PASSWD ? DBADMIN_PASSWD : $this->_parsedDSN['password']);
108 } catch (PDOException $e) {
109 echo "<br>\nDB Connection failed: " . $e->getMessage();
110 echo "<br>\nDSN: '", $this->_dsn, "'";
111 echo "<br>\n_parsedDSN: '", print_r($this->_parsedDSN), "'";
117 $sth = $conn->prepare("SHOW COLUMNS FROM $table");
119 $field_list = array();
120 while ($row = $sth->fetch(PDO::FETCH_NUM)) {
121 $field_list[] = $row[0];
123 if ($database != $old_db) {
130 * offset specific syntax within mysql
131 * convert from,count to SQL "LIMIT $offset, $count"
133 function _limit_sql($limit = false)
136 list($offset, $count) = $this->limit($limit);
138 // pgsql needs "LIMIT $count OFFSET $from"
139 $limit = " LIMIT $offset, $count";
141 $limit = " LIMIT $count";
153 // c-hanging-comment-ender-p: nil
154 // indent-tabs-mode: nil