ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilDBPdoMySQL Class Reference

Class ilDBPdoMySQL. More...

+ Inheritance diagram for ilDBPdoMySQL:
+ Collaboration diagram for ilDBPdoMySQL:

Public Member Functions

 supportsTransactions ()
 
 initHelpers ()
 
 supportsEngineMigration ()
 
 migrateAllTablesToEngine ($engine=ilDBConstants::MYSQL_ENGINE_INNODB)
 
 migrateAllTablesToCollation ($collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
 @inheritDoc More...
 
 supportsCollationMigration ()
 @inheritDoc More...
 
 nextId ($table_name)
 
 doesCollationSupportMB4Strings ()
 @inheritDoc More...
 
- Public Member Functions inherited from ilDBPdo
 connect ($return_false_for_error=false)
 
 initHelpers ()
 
 getFieldDefinition ()
 
 setFieldDefinition ($field_definition)
 
 createDatabase ($a_name, $a_charset="utf8", $a_collation="")
 
 getLastErrorCode ()
 
 initFromIniFile ($tmpClientIniFile=null)
 
 generateDSN ()
 
 quoteIdentifier ($identifier, $check_option=false)
 
 nextId ($table_name)
 
 createTable ($table_name, $fields, $drop_table=false, $ignore_erros=false)
 
 checkColumnName ($a_name)
 
 addPrimaryKey ($table_name, $primary_keys)
 
 dropIndexByFields ($table_name, $fields)
 
 getPrimaryKeyIdentifier ()
 
 createSequence ($table_name, $start=1)
 
 tableExists ($table_name)
 
 tableColumnExists ($table_name, $column_name)
 
 addTableColumn ($table_name, $column_name, $attributes)
 
 dropTable ($table_name, $error_if_not_existing=true)
 
 query ($query)
 
 dropSequence ($table_name)
 
 dropTableColumn ($table_name, $column_name)
 
 renameTableColumn ($table_name, $column_old_name, $column_new_name)
 
 insert ($table_name, $values)
 
 fetchObject ($query_result)
 
 update ($table_name, $columns, $where)
 
 manipulate ($query)
 
 fetchAssoc ($query_result)
 
 numRows ($query_result)
 
 quote ($value, $type=null)
 
 indexExistsByFields ($table_name, $fields)
 
 addIndex ($table_name, $fields, $index_name='', $fulltext=false)
 
 addFulltextIndex ($a_table, $a_fields, $a_name="in")
 
 dropFulltextIndex ($a_table, $a_name)
 Drop fulltext index. More...
 
 isFulltextIndex ($a_table, $a_name)
 Is index a fulltext index? More...
 
 getIndexName ($index_name_base)
 
 getSequenceName ($table_name)
 
 constraintName ($a_table, $a_constraint)
 Determine contraint name by table name and constraint name. More...
 
 getDSN ()
 
 getDBType ()
 
 setDBType ($type)
 
 lockTables ($tables)
 
 unlockTables ()
 
 in ($field, $values, $negate=false, $type="")
 
 queryF ($query, $types, $values)
 
 manipulateF ($query, $types, $values)
 
 useSlave ($bool)
 
 setLimit ($limit, $offset=0)
 Set the Limit for the next Query. More...
 
 like ($column, $type, $value="?", $case_insensitive=true)
 
 now ()
 
 replace ($table, $primaryKeys, $otherColumns)
 Replace into method. More...
 
 equals ($columns, $value, $type, $emptyOrNull=false)
 
 getHost ()
 
 setHost ($host)
 
 getDbname ()
 
 setDbname ($dbname)
 
 getCharset ()
 
 setCharset ($charset)
 
 getUsername ()
 
 setUsername ($username)
 
 getPassword ()
 
 setPassword ($password)
 
 getPort ()
 
 setPort ($port)
 
 setDBUser ($user)
 
 setDBPort ($port)
 
 setDBPassword ($password)
 
 setDBHost ($host)
 
 upper ($a_exp)
 
 lower ($a_exp)
 
 substr ($a_exp, $a_pos=1, $a_len=-1)
 
 prepareManip ($query, $types=null)
 
 prepare ($query, $types=null, $result_types=null)
 
 enableResultBuffering ($a_status)
 
 supportsSlave ()
 
 supportsFulltext ()
 
 supportsTransactions ()
 
 supports ($feature)
 
 listTables ()
 
 loadModule ($module)
 
 getAllowedAttributes ()
 
Returns
array
More...
 
 sequenceExists ($sequence)
 
 listSequences ()
 
 concat (array $values, $allow_null=true)
 
 locate ($a_needle, $a_string, $a_start_pos=1)
 
 modifyTableColumn ($table, $a_column, $a_attributes)
 
 renameTable ($a_name, $a_new_name)
 
 checkTableName ($a_name)
 
 beginTransaction ()
 
 commit ()
 
 rollback ()
 
 dropIndex ($a_table, $a_name="i1")
 
 setStorageEngine ($storage_engine)
 
 getStorageEngine ()
 
 queryCol ($query, $type=PDO::FETCH_ASSOC, $colnum=0)
 
 queryRow ($query, $types=null, $fetchmode=ilDBConstants::FETCHMODE_DEFAULT)
 
 getServerVersion ($native=false)
 
 escape ($value, $escape_wildcards=false)
 
 escapePattern ($text)
 
 migrateAllTablesToEngine ($engine=ilDBConstants::MYSQL_ENGINE_INNODB)
 
 migrateAllTablesToCollation ($collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
 @inheritDoc More...
 
 supportsCollationMigration ()
 @inheritDoc More...
 
 supportsEngineMigration ()
 
 checkIndexName ($name)
 
 addUniqueConstraint ($table, $fields, $name="con")
 
 dropUniqueConstraint ($a_table, $a_name="con")
 
 dropUniqueConstraintByFields ($a_table, $a_fields)
 
 getLastInsertId ()
 
 buildAtomQuery ()
 
 uniqueConstraintExists ($table, array $fields)
 
 dropPrimaryKey ($table_name)
 
 executeMultiple ($stmt, $a_data)
 
 fromUnixtime ($a_expr, $a_to_text=true)
 
 unixTimestamp ()
 
 autoExecute ($tablename, $fields, $mode=ilDBConstants::MDB2_AUTOQUERY_INSERT, $where=false)
 Generate an insert, update or delete query and call prepare() and execute() on it. More...
 
 getDBVersion ()
 
 sanitizeMB4StringIfNotSupported ($query)
 
Parameters
$querystring to sanitize, all MB4-Characters like emojis will re replaced with ???
Returns
string sanitized query
More...
 
 doesCollationSupportMB4Strings ()
 @inheritDoc More...
 
 groupConcat ($a_field_name, $a_seperator=",", $a_order=null)
 
Parameters
string$a_field_name
string$a_seperator
string$a_order
Returns
string
More...
 
 cast ($a_field_name, $a_dest_type)
 
Parameters
string$a_field_name
string$a_dest_type
Returns
string;
More...
 
- Public Member Functions inherited from ilDBInterface
 doesCollationSupportMB4Strings ()
 
 sanitizeMB4StringIfNotSupported ($query)
 
 initFromIniFile ($tmpClientIniFile=null)
 
 connect ($return_false_on_error=false)
 
 nextId ($table_name)
 
 createTable ($table_name, $fields, $drop_table=false, $ignore_erros=false)
 
 addPrimaryKey ($table_name, $primary_keys)
 
 createSequence ($table_name, $start=1)
 
 getSequenceName ($table_name)
 
 tableExists ($table_name)
 
 tableColumnExists ($table_name, $column_name)
 
 addTableColumn ($table_name, $column_name, $attributes)
 
 dropTable ($table_name, $error_if_not_existing=true)
 
 renameTable ($old_name, $new_name)
 
 query ($query)
 Run a (read-only) Query on the database. More...
 
 fetchAll ($query_result, $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
 
 dropSequence ($table_name)
 
 dropTableColumn ($table_name, $column_name)
 
 renameTableColumn ($table_name, $column_old_name, $column_new_name)
 
 insert ($table_name, $values)
 
 fetchObject ($query_result)
 
 update ($table_name, $values, $where)
 
 manipulate ($query)
 Run a (write) Query on the database. More...
 
 fetchAssoc ($query_result)
 
 numRows ($query_result)
 
 quote ($value, $type)
 
 addIndex ($table_name, $fields, $index_name='', $fulltext=false)
 
 indexExistsByFields ($table_name, $fields)
 
 getDSN ()
 Get DSN. More...
 
 getDBType ()
 Get DSN. More...
 
 lockTables ($tables)
 Abstraction of lock table. More...
 
 unlockTables ()
 Unlock tables locked by previous lock table calls. More...
 
 in ($field, $values, $negate=false, $type="")
 
 queryF ($query, $types, $values)
 
 manipulateF ($query, $types, $values)
 
 useSlave ($bool)
 Return false iff slave is not supported. More...
 
 setLimit ($limit, $offset)
 
 like ($column, $type, $value="?", $case_insensitive=true)
 Generate a like subquery. More...
 
 now ()
 
 replace ($table, $primaryKeys, $otherColumns)
 Replace into method. More...
 
 equals ($columns, $value, $type, $emptyOrNull=false)
 
 setDBUser ($user)
 
 setDBPort ($port)
 
 setDBPassword ($password)
 
 setDBHost ($host)
 
 upper ($a_exp)
 
 lower ($a_exp)
 
 substr ($a_exp)
 
 prepare ($a_query, $a_types=null, $a_result_types=null)
 Prepare a query (SELECT) statement to be used with execute. More...
 
 prepareManip ($a_query, $a_types=null)
 
 enableResultBuffering ($a_status)
 
 execute ($stmt, $data=array())
 
 sequenceExists ($sequence)
 
 listSequences ()
 
 supports ($feature)
 
 supportsFulltext ()
 
 supportsSlave ()
 
 supportsTransactions ()
 
 listTables ()
 
 loadModule ($module)
 
 getAllowedAttributes ()
 
 concat (array $values, $allow_null=true)
 
 locate ($a_needle, $a_string, $a_start_pos=1)
 
 quoteIdentifier ($identifier, $check_option=false)
 
 modifyTableColumn ($table, $column, $attributes)
 
 free ($a_st)
 
 checkTableName ($a_name)
 
 beginTransaction ()
 
 commit ()
 
 rollback ()
 
 constraintName ($a_table, $a_constraint)
 
 dropIndex ($a_table, $a_name="i1")
 
 createDatabase ($a_name, $a_charset="utf8", $a_collation="")
 
 dropIndexByFields ($table_name, $afields)
 
 getPrimaryKeyIdentifier ()
 
 addFulltextIndex ($table_name, $afields, $a_name='in')
 
 dropFulltextIndex ($a_table, $a_name)
 
 isFulltextIndex ($a_table, $a_name)
 
 setStorageEngine ($storage_engine)
 
 getStorageEngine ()
 
 buildAtomQuery ()
 
 groupConcat ($a_field_name, $a_seperator=",", $a_order=null)
 
 cast ($a_field_name, $a_dest_type)
 
 getServerVersion ($native=false)
 
 queryCol ($query, $type=ilDBConstants::FETCHMODE_DEFAULT, $colnum=0)
 
 queryRow ($query, $types=null, $fetchmode=ilDBConstants::FETCHMODE_DEFAULT)
 
 escape ($value, $escape_wildcards=false)
 
 escapePattern ($text)
 
 migrateAllTablesToEngine ($engine=ilDBConstants::MYSQL_ENGINE_INNODB)
 
 supportsEngineMigration ()
 
 migrateAllTablesToCollation ($collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
 
 supportsCollationMigration ()
 
 addUniqueConstraint ($table, $fields, $name="con")
 
 dropUniqueConstraint ($table, $name="con")
 
 dropUniqueConstraintByFields ($table, $fields)
 
 checkIndexName ($name)
 
 getLastInsertId ()
 
 prepare ($query, $types=null, $result_types=null)
 
 uniqueConstraintExists ($table, array $fields)
 
 dropPrimaryKey ($table_name)
 
 executeMultiple ($stmt, $data)
 
 fromUnixtime ($expr, $to_text=true)
 
 unixTimestamp ()
 
 autoExecute ($tablename, $fields, $mode=ilDBConstants::MDB2_AUTOQUERY_INSERT, $where=false)
 Generate an insert, update or delete query and call prepare() and execute() on it. More...
 
 getDBVersion ()
 returns the Version of the Database (e.g. More...
 

Protected Member Functions

 initSQLMode ()
 
 getAdditionalAttributes ()
 
- Protected Member Functions inherited from ilDBPdo
 initSQLMode ()
 
 getAttributes ()
 
 getAdditionalAttributes ()
 
 checkTableColumns ($a_cols)
 
 checkColumn ($a_col, $a_def)
 
 checkColumnDefinition ($a_def, $a_modify_mode=false)
 
 appendLimit ($query)
 
 autoPrepare ($table, $table_fields, $mode=ilDBConstants::MDB2_AUTOQUERY_INSERT, $where=false, $types=null, $result_types=ilDBConstants::MDB2_PREPARE_MANIP)
 
 buildManipSQL ($table, $table_fields, $mode, $where=false)
 

Additional Inherited Members

- Static Public Member Functions inherited from ilDBPdo
static isReservedWord ($a_word)
 
- Static Public Member Functions inherited from ilDBInterface
static getReservedWords ()
 Get reserved words. More...
 
static isReservedWord ($a_word)
 
- Data Fields inherited from ilDBPdo
const FEATURE_TRANSACTIONS = 'transactions'
 
const FEATURE_FULLTEXT = 'fulltext'
 
const FEATURE_SLAVE = 'slave'
 
- Protected Attributes inherited from ilDBPdo
 $host = ''
 
 $dbname = ''
 
 $charset = 'utf8'
 
 $username = ''
 
 $password = ''
 
 $port = 3306
 
 $pdo
 
 $manager
 
 $reverse
 
 $limit = null
 
 $offset = null
 
 $storage_engine = 'MyISAM'
 
 $dsn = ''
 
 $attributes
 
 $db_type = ''
 
 $error_code = 0
 
 $field_definition
 

Detailed Description

Class ilDBPdoMySQL.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 11 of file class.ilDBPdoMySQL.php.

Member Function Documentation

◆ doesCollationSupportMB4Strings()

ilDBPdoMySQL::doesCollationSupportMB4Strings ( )

@inheritDoc

Reimplemented from ilDBPdo.

Definition at line 141 of file class.ilDBPdoMySQL.php.

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 }

◆ getAdditionalAttributes()

ilDBPdoMySQL::getAdditionalAttributes ( )
protected
Returns
array

Reimplemented from ilDBPdo.

Definition at line 49 of file class.ilDBPdoMySQL.php.

50 {
51 return array(
52 PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
53 PDO::ATTR_TIMEOUT => 300 * 60,
54 );
55 }

◆ initHelpers()

ilDBPdoMySQL::initHelpers ( )

Reimplemented from ilDBPdo.

Definition at line 23 of file class.ilDBPdoMySQL.php.

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 }
Class ilDBPdoManager.
Class ilDBPdoMySQLFieldDefinition.
Class ilDBPdoReverse.

◆ initSQLMode()

ilDBPdoMySQL::initSQLMode ( )
protected

Reimplemented from ilDBPdo.

Definition at line 31 of file class.ilDBPdoMySQL.php.

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 }

◆ migrateAllTablesToCollation()

ilDBPdoMySQL::migrateAllTablesToCollation (   $collation = ilDBConstants::MYSQL_COLLATION_UTF8MB4)

@inheritDoc

Reimplemented from ilDBPdo.

Definition at line 85 of file class.ilDBPdoMySQL.php.

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 }
loadModule($module)
$errors
Definition: index.php:6

References $errors, ilDBPdo\loadModule(), and ilDBConstants\MODULE_MANAGER.

+ Here is the call graph for this function:

◆ migrateAllTablesToEngine()

ilDBPdoMySQL::migrateAllTablesToEngine (   $engine = ilDBConstants::MYSQL_ENGINE_INNODB)
Parameters
string$engine
Returns
array

Reimplemented from ilDBPdo.

Definition at line 62 of file class.ilDBPdoMySQL.php.

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 }
queryCol($query, $type=PDO::FETCH_ASSOC, $colnum=0)
if(empty($password)) $table
Definition: pwgen.php:24
$engine
Definition: workflow.php:89

References $engine, $errors, $table, ilDBPdo\listTables(), and ilDBPdo\queryCol().

+ Here is the call graph for this function:

◆ nextId()

ilDBPdoMySQL::nextId (   $table_name)
Parameters
string$table_name
Returns
int

Reimplemented from ilDBPdo.

Definition at line 115 of file class.ilDBPdoMySQL.php.

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 }
$result
query($query)
getSequenceName($table_name)
quoteIdentifier($identifier, $check_option=false)
$query

References $query, $result, ilDBPdo\getSequenceName(), ilDBPdo\query(), and ilDBPdo\quoteIdentifier().

+ Here is the call graph for this function:

◆ supportsCollationMigration()

ilDBPdoMySQL::supportsCollationMigration ( )

@inheritDoc

Reimplemented from ilDBPdo.

Definition at line 105 of file class.ilDBPdoMySQL.php.

106 {
107 return true;
108 }

◆ supportsEngineMigration()

ilDBPdoMySQL::supportsEngineMigration ( )
Returns
bool

Reimplemented from ilDBPdo.

Definition at line 40 of file class.ilDBPdoMySQL.php.

41 {
42 return true;
43 }

◆ supportsTransactions()

ilDBPdoMySQL::supportsTransactions ( )
Returns
bool

Reimplemented from ilDBPdo.

Reimplemented in ilDBPdoMySQLGalera, and ilDBPdoMySQLInnoDB.

Definition at line 17 of file class.ilDBPdoMySQL.php.

18 {
19 return false;
20 }

The documentation for this class was generated from the following file: