5 Copyright 2005 $ThePhpWikiProgrammingTeam
7 This file is part of PhpWiki.
9 PhpWiki is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 PhpWiki is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with PhpWiki; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * @author: Reini Urban
27 require_once('lib/WikiDB/backend/PDO.php');
29 class WikiDB_backend_PDO_mysql
30 extends WikiDB_backend_PDO
32 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() {
65 * Kill timed out processes. ( so far only called on about every 50-th save. )
68 if (empty($this->_dbparams['timeout'])) return;
69 $sth = $this->_dbh->prepare("SHOW processlist");
71 while ($row = $sth->fetch(PDO_FETCH_ASSOC)) {
72 if ($row["db"] == $this->_dsn['database']
73 and $row["User"] == $this->_dsn['username']
74 and $row["Time"] > $this->_dbparams['timeout']
75 and $row["Command"] == "Sleep")
77 $process_id = $row["Id"];
78 $this->query("KILL $process_id");
89 foreach ($this->_table_names as $table) {
90 $this->query("OPTIMIZE TABLE $table");
95 function listOfTables() {
96 $sth = $this->_dbh->prepare("SHOW TABLES");
99 while ($row = $sth->fetch(PDO_FETCH_NUM)) { $tables[] = $row[0]; }
103 function listOfFields($database, $table) {
104 $old_db = $this->database();
105 if ($database != $old_db) {
107 $dsn = preg_replace("/dbname=\w+;/", "dbname=".$database, $this->_dsn);
108 $dsn = preg_replace("/database=\w+;/", "database=".$database, $dsn);
109 $conn = new PDO($dsn,
110 DBADMIN_USER ? DBADMIN_USER : $this->_parsedDSN['username'],
111 DBADMIN_PASSWD ? DBADMIN_PASSWD : $this->_parsedDSN['password']);
113 catch (PDOException $e) {
114 echo "<br>\nDB Connection failed: " . $e->getMessage();
115 echo "<br>\nDSN: '", $this->_dsn, "'";
116 echo "<br>\n_parsedDSN: '", print_r($this->_parsedDSN), "'";
122 $sth = $conn->prepare("SHOW COLUMNS FROM $table");
124 $field_list = array();
125 while ($row = $sth->fetch(PDO_FETCH_NUM)) {
126 $field_list[] = $row[0];
128 if ($database != $old_db) {
135 * offset specific syntax within mysql
136 * convert from,count to SQL "LIMIT $offset, $count"
138 function _limit_sql($limit = false) {
140 list($offset, $count) = $this->limit($limit);
142 // pgsql needs "LIMIT $count OFFSET $from"
143 $limit = " LIMIT $offset, $count";
145 $limit = " LIMIT $count";
157 // c-hanging-comment-ender-p: nil
158 // indent-tabs-mode: nil