ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 */
3
9abstract class ilDBPdoMySQL extends ilDBPdo implements ilDBInterface
10{
11
15 public function supportsTransactions()
16 {
17 return false;
18 }
19
20
21 public function initHelpers()
22 {
23 $this->manager = new ilDBPdoManager($this->pdo, $this);
24 $this->reverse = new ilDBPdoReverse($this->pdo, $this);
25 $this->field_definition = new ilDBPdoMySQLFieldDefinition($this);
26 }
27
28
29 protected function initSQLMode()
30 {
31 $this->pdo->query("SET SESSION sql_mode = 'IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';");
32 }
33
34
38 public function supportsEngineMigration()
39 {
40 return true;
41 }
42
43
47 protected function getAdditionalAttributes()
48 {
49 return array(
50 PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
51 PDO::ATTR_TIMEOUT => 300 * 60,
52 );
53 }
54
55
61 {
62 $engines = $this->queryCol('SHOW ENGINES');
63 if (!in_array($engine, $engines)) {
64 return array();
65 }
66
67 $errors = array();
68 foreach ($this->listTables() as $table) {
69 try {
70 $this->pdo->exec("ALTER TABLE {$table} ENGINE={$engine}");
71 } catch (Exception $e) {
72 $errors[$table] = $e->getMessage();
73 }
74 }
75
76 return $errors;
77 }
78
79
84 {
85 $ilDBPdoManager = $this->loadModule(ilDBConstants::MODULE_MANAGER);
86 $errors = array();
87 foreach ($ilDBPdoManager->listTables() as $table_name) {
88 $q = "ALTER TABLE {$this->quoteIdentifier($table_name)} CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;";
89 try {
90 $this->pdo->exec($q);
91 } catch (PDOException $e) {
92 $errors[] = $table_name;
93 }
94 }
95
96 return $errors;
97 }
98
99
104 {
105 return true;
106 }
107
108
113 public function nextId($table_name)
114 {
115 $sequence_name = $this->quoteIdentifier($this->getSequenceName($table_name), true);
116 $seqcol_name = 'sequence';
117 $query = "INSERT INTO $sequence_name ($seqcol_name) VALUES (NULL)";
118 try {
119 $this->pdo->exec($query);
120 } catch (PDOException $e) {
121 // no such table check
122 }
123
124 $result = $this->query('SELECT LAST_INSERT_ID() AS next');
125 $value = $result->fetchObject()->next;
126
127 if (is_numeric($value)) {
128 $query = "DELETE FROM $sequence_name WHERE $seqcol_name < $value";
129 $this->pdo->exec($query);
130 }
131
132 return $value;
133 }
134
135
140 {
141 // Currently ILIAS does not support utf8mb4, after that ilDB could check like this:
142 // static $supported;
143 // if (!isset($supported)) {
144 // $q = "SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = %s;";
145 // $res = $this->queryF($q, ['text'], [$this->getDbname()]);
146 // $data = $this->fetchObject($res);
147 // $supported = ($data->default_character_set_name === 'utf8mb4');
148 // }
149
150 return false;
151 }
152}
$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.
$query
$errors
$engine
Definition: workflow.php:89