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) {
48 $aliases = array('iso-8859-1' => 'latin1',
50 //http://dev.mysql.com/doc/mysql/en/charset-connection.html
51 if (isset($aliases[strtolower($charset)])) {
52 // mysql needs special unusual names and doesn't resolve aliases
53 mysql_query("SET NAMES '" . $aliases[$charset] . "'");
55 mysql_query("SET NAMES '$charset'");
60 function backendType()
66 * Kill timed out processes. ( so far only called on about every 50-th save. )
70 if (empty($this->_dbparams['timeout'])) return;
71 $sth = $this->_dbh->prepare("SHOW processlist");
73 while ($row = $sth->fetch(PDO_FETCH_ASSOC)) {
74 if ($row["db"] == $this->_dsn['database']
75 and $row["User"] == $this->_dsn['username']
76 and $row["Time"] > $this->_dbparams['timeout']
77 and $row["Command"] == "Sleep"
79 $process_id = $row["Id"];
80 $this->query("KILL $process_id");
92 foreach ($this->_table_names as $table) {
93 $this->query("OPTIMIZE TABLE $table");
98 function listOfTables()
100 $sth = $this->_dbh->prepare("SHOW TABLES");
103 while ($row = $sth->fetch(PDO_FETCH_NUM)) {
109 function listOfFields($database, $table)
111 $old_db = $this->database();
112 if ($database != $old_db) {
114 $dsn = preg_replace("/dbname=\w+;/", "dbname=" . $database, $this->_dsn);
115 $dsn = preg_replace("/database=\w+;/", "database=" . $database, $dsn);
116 $conn = new PDO($dsn,
117 DBADMIN_USER ? DBADMIN_USER : $this->_parsedDSN['username'],
118 DBADMIN_PASSWD ? DBADMIN_PASSWD : $this->_parsedDSN['password']);
119 } catch (PDOException $e) {
120 echo "<br>\nDB Connection failed: " . $e->getMessage();
121 echo "<br>\nDSN: '", $this->_dsn, "'";
122 echo "<br>\n_parsedDSN: '", print_r($this->_parsedDSN), "'";
128 $sth = $conn->prepare("SHOW COLUMNS FROM $table");
130 $field_list = array();
131 while ($row = $sth->fetch(PDO_FETCH_NUM)) {
132 $field_list[] = $row[0];
134 if ($database != $old_db) {
141 * offset specific syntax within mysql
142 * convert from,count to SQL "LIMIT $offset, $count"
144 function _limit_sql($limit = false)
147 list($offset, $count) = $this->limit($limit);
149 // pgsql needs "LIMIT $count OFFSET $from"
150 $limit = " LIMIT $offset, $count";
152 $limit = " LIMIT $count";
164 // c-hanging-comment-ender-p: nil
165 // indent-tabs-mode: nil