ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilDBPdoMySQL.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3require_once('./Services/Database/classes/PDO/FieldDefinition/class.ilDBPdoMySQLFieldDefinition.php');
4require_once('class.ilDBPdo.php');
5
11abstract class ilDBPdoMySQL extends ilDBPdo implements ilDBInterface
12{
13
17 public function supportsTransactions()
18 {
19 return false;
20 }
21
22
23 public function initHelpers()
24 {
25 $this->manager = new ilDBPdoManager($this->pdo, $this);
26 $this->reverse = new ilDBPdoReverse($this->pdo, $this);
27 $this->field_definition = new ilDBPdoMySQLFieldDefinition($this);
28 }
29
30
31 protected function initSQLMode()
32 {
33 $this->pdo->query("SET SESSION sql_mode = 'IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';");
34 }
35
36
40 public function supportsEngineMigration()
41 {
42 return true;
43 }
44
45
49 protected function getAdditionalAttributes()
50 {
51 return array(
52 PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
53 PDO::ATTR_TIMEOUT => 300 * 60,
54 );
55 }
56
57
63 {
64 $engines = $this->queryCol('SHOW ENGINES');
65 if (!in_array($engine, $engines)) {
66 return array();
67 }
68
69 $errors = array();
70 foreach ($this->listTables() as $table) {
71 try {
72 $this->pdo->exec("ALTER TABLE {$table} ENGINE={$engine}");
73 } catch (Exception $e) {
74 $errors[$table] = $e->getMessage();
75 }
76 }
77
78 return $errors;
79 }
80
81
86 {
87 $ilDBPdoManager = $this->loadModule(ilDBConstants::MODULE_MANAGER);
88 $errors = array();
89 foreach ($ilDBPdoManager->listTables() as $table_name) {
90 $q = "ALTER TABLE {$this->quoteIdentifier($table_name)} CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;";
91 try {
92 $this->pdo->exec($q);
93 } catch (PDOException $e) {
94 $errors[] = $table_name;
95 }
96 }
97
98 return $errors;
99 }
100
101
106 {
107 return true;
108 }
109
110
115 public function nextId($table_name)
116 {
117 $sequence_name = $this->quoteIdentifier($this->getSequenceName($table_name), true);
118 $seqcol_name = 'sequence';
119 $query = "INSERT INTO $sequence_name ($seqcol_name) VALUES (NULL)";
120 try {
121 $this->pdo->exec($query);
122 } catch (PDOException $e) {
123 // no such table check
124 }
125
126 $result = $this->query('SELECT LAST_INSERT_ID() AS next');
127 $value = $result->fetchObject()->next;
128
129 if (is_numeric($value)) {
130 $query = "DELETE FROM $sequence_name WHERE $seqcol_name < $value";
131 $this->pdo->exec($query);
132 }
133
134 return $value;
135 }
136
137
142 {
143 // Currently ILIAS does not support utf8mb4, after that ilDB could check like this:
144 // static $supported;
145 // if (!isset($supported)) {
146 // $q = "SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = %s;";
147 // $res = $this->queryF($q, ['text'], [$this->getDbname()]);
148 // $data = $this->fetchObject($res);
149 // $supported = ($data->default_character_set_name === 'utf8mb4');
150 // }
151
152 return false;
153 }
154}
$result
An exception for terminatinating execution or to throw for unit testing.
Class ilDBPdoManager.
Class ilDBPdoMySQLFieldDefinition.
Class ilDBPdoMySQL.
nextId($table_name)
supportsCollationMigration()
@inheritDoc
doesCollationSupportMB4Strings()
@inheritDoc
migrateAllTablesToEngine($engine=ilDBConstants::MYSQL_ENGINE_INNODB)
migrateAllTablesToCollation($collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
@inheritDoc
Class ilDBPdoReverse.
Class pdoDB.
loadModule($module)
query($query)
getSequenceName($table_name)
quoteIdentifier($identifier, $check_option=false)
queryCol($query, $type=PDO::FETCH_ASSOC, $colnum=0)
Interface ilDBInterface.
$errors
Definition: index.php:6
$query
if(empty($password)) $table
Definition: pwgen.php:24
$engine
Definition: workflow.php:89