19declare(strict_types=1);
57 'STRICT_TRANS_TABLES',
62 'ERROR_FOR_DIVISION_BY_ZERO',
63 'NO_ENGINE_SUBSTITUTION',
73 public function connect(
bool $return_false_for_error =
false): ?bool
79 $this->pdo->exec(
"SET SESSION sql_mode = '" . implode(
",", self::SESSION_MODES) .
"';");
83 }
catch (Exception
$e) {
84 $this->error_code =
$e->getCode();
85 if ($return_false_for_error) {
91 return ($this->pdo->errorCode() === PDO::ERR_NONE);
104 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
105 PDO::MYSQL_ATTR_USE_BUFFERED_QUERY =>
true,
106 PDO::ATTR_TIMEOUT => 300 * 60,
120 public function createDatabase(
string $a_name,
string $a_charset =
"utf8",
string $a_collation =
""): bool
126 $this->
query($this->manager->getQueryUtils()->createDatabase($a_name, $a_charset, $a_collation));
128 }
catch (PDOException) {
138 if ($this->pdo instanceof PDO) {
139 return $this->pdo->errorCode();
150 $clientIniFile =
$ini;
151 } elseif (
$DIC->offsetExists(
'ilClientIniFile')) {
152 $clientIniFile =
$DIC[
'ilClientIniFile'];
154 throw new InvalidArgumentException(
'$tmpClientIniFile is not an instance of ilIniFile');
157 $this->
setUsername($clientIniFile->readVariable(
"db",
"user"));
158 $this->
setHost($clientIniFile->readVariable(
"db",
"host"));
159 $this->
setPort((
int) $clientIniFile->readVariable(
"db",
"port"));
160 $this->
setPassword((
string) $clientIniFile->readVariable(
"db",
"pass"));
161 $this->
setDbname($clientIniFile->readVariable(
"db",
"name"));
162 $this->
setDBType($clientIniFile->readVariable(
"db",
"type"));
176 public function quoteIdentifier(
string $identifier,
bool $check_option =
false): string
178 return '`' . preg_replace(
'/[^a-zA-Z0-9_$]/',
'', $identifier) .
'`';
186 $query =
"INSERT INTO $sequence_name ($seqcol_name) VALUES (NULL)";
188 $this->pdo->exec($query);
189 }
catch (PDOException) {
193 $result = $this->
query(
'SELECT LAST_INSERT_ID() AS next');
194 $value = $result->fetchObject()->next;
196 if (is_numeric($value)) {
197 $query =
"DELETE FROM $sequence_name WHERE $seqcol_name < $value";
198 $this->pdo->exec($query);
210 bool $drop_table =
false,
211 bool $ignore_erros =
false
227 return $this->manager->createTable($table_name, $fields, []);
232 foreach ($a_cols as $col => $def) {
233 if (!$this->checkColumn($col, $def)) {
243 if (!$this->checkColumnName($a_col)) {
246 return $this->checkColumnDefinition($a_def);
251 return $this->field_definition->checkColumnDefinition($a_def);
256 return $this->field_definition->checkColumnName($a_name);
262 public function addPrimaryKey(
string $table_name, array $primary_keys): bool
265 foreach ($primary_keys as
$f) {
272 $this->manager->createConstraint(
274 $this->constraintName($table_name, $this->getPrimaryKeyIdentifier()),
286 foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
287 $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
288 $idx_fields = array_keys($def[
'fields']);
290 if ($idx_fields === $fields) {
291 return $this->dropIndex($table_name, $idx_name);
305 $this->manager->createSequence($table_name, $start);
311 $result = $this->pdo->prepare(
"SHOW TABLES LIKE :table_name");
312 $result->execute([
'table_name' => $table_name]);
313 $return = $result->rowCount();
314 $result->closeCursor();
321 return in_array($column_name, $this->manager->listTableFields($table_name),
true);
327 public function addTableColumn(
string $table_name,
string $column_name, array $attributes): bool
329 if (!$this->checkColumnName($column_name)) {
330 throw new ilDatabaseException(
"ilDB Error: addTableColumn(" . $table_name .
", " . $column_name .
")");
332 if (!$this->checkColumnDefinition($attributes)) {
333 throw new ilDatabaseException(
"ilDB Error: addTableColumn(" . $table_name .
", " . $column_name .
")");
338 $column_name => $attributes,
342 return $this->manager->alterTable($table_name, $changes,
false);
348 public function dropTable(
string $table_name,
bool $error_if_not_existing =
true): bool
350 $tables = $this->manager->listTables();
351 $table_exists = in_array($table_name, $tables);
352 if (!$table_exists && $error_if_not_existing) {
357 $sequences = $this->manager->listSequences();
358 if (in_array($table_name, $sequences)) {
359 $this->manager->dropSequence($table_name);
364 $this->manager->dropTable($table_name);
376 $ilBench =
$DIC[
'ilBench'] ??
null;
378 $query = $this->appendLimit($query);
382 $ilBench->startDbBench($query);
384 $res = $this->pdo->query($query);
386 $ilBench->stopDbBench();
388 }
catch (PDOException
$e) {
392 $err = $this->pdo->errorCode();
393 if ($err !== PDO::ERR_NONE) {
394 $info = $this->pdo->errorInfo();
395 $info_message =
$info[2];
405 while (
$data = $statement->
fetch($fetch_mode)) {
414 $this->manager->dropSequence($table_name);
429 return $this->manager->alterTable($table_name, $changes,
false);
435 public function renameTableColumn(
string $table_name,
string $column_old_name,
string $column_new_name): bool
438 if (!$this->checkColumnName($column_new_name)) {
439 throw new ilDatabaseException(
"ilDB Error: renameTableColumn(" . $table_name .
"," . $column_old_name .
"," . $column_new_name .
")");
442 $def = $this->reverse->getTableFieldDefinition($table_name, $column_old_name);
445 $best_alt = $analyzer->getBestDefinitionAlternative($def);
446 $def = $def[$best_alt];
447 unset($def[
"nativetype"]);
448 unset($def[
"mdb2type"]);
450 $f[
"definition"] = $def;
451 $f[
"name"] = $column_new_name;
455 $column_old_name =>
$f,
459 return $this->manager->alterTable($table_name, $changes,
false);
462 public function insert(
string $table_name, array $values):
int
466 foreach ($values as $key => $val) {
467 $real[] = $this->quote($val[1], $val[0]);
468 $fields[] = $this->quoteIdentifier($key);
470 $values_string = implode(
",", $real);
471 $fields_string = implode(
",", $fields);
472 $query =
"INSERT INTO " . $this->quoteIdentifier($table_name) .
" (" . $fields_string .
") VALUES (" . $values_string .
")";
474 $query = $this->sanitizeMB4StringIfNotSupported($query);
476 return (
int) $this->pdo->exec($query);
483 $query_result->closeCursor();
491 public function update(
string $table_name, array $columns, array $where):
int
496 $placeholders_full = [];
501 foreach ($columns as $k => $col) {
502 $field_value = $col[1];
504 $placeholders[] =
"%s";
505 $placeholders_full[] =
":$k";
508 if (($col[0] ===
"blob" || $col[0] ===
"clob" || $col[0] ===
'text') && is_string($field_value)) {
509 $field_value = $this->sanitizeMB4StringIfNotSupported($field_value);
513 if ($col[0] ===
'integer' && !is_null($field_value)) {
514 $field_value = (
int) $field_value;
517 $values[] = $field_value;
518 $field_values[$k] = $field_value;
519 if ($col[0] ===
"blob" || $col[0] ===
"clob") {
525 $q =
"UPDATE " . $this->quoteIdentifier($table_name) .
" SET ";
527 foreach ($fields as $k => $field) {
528 $q .= $lim . $this->quoteIdentifier($field) .
" = " . $placeholders_full[$k];
533 foreach ($where as $k => $col) {
534 $q .= $lim . $this->quoteIdentifier($k) .
" = " . $this->quote($col[1], $col[0]);
538 $r = $this->prepareManip(
$q, $types);
539 $this->execute($r, $field_values);
541 $num_affected_rows = $r->rowCount();
545 foreach ($where as $k => $col) {
548 $field_values[$k] = $col;
550 $q =
"UPDATE " . $this->quoteIdentifier($table_name) .
" SET ";
552 foreach ($fields as $k => $field) {
553 $q .= $lim . $this->quoteIdentifier($field) .
" = " . $placeholders[$k];
558 foreach (array_keys($where) as $k) {
559 $q .= $lim . $this->quoteIdentifier($k) .
" = %s";
563 $num_affected_rows = $this->manipulateF(
$q, $types, $values);
566 return $num_affected_rows;
575 $ilBench =
$DIC[
'ilBench'] ??
null;
577 $query = $this->sanitizeMB4StringIfNotSupported($query);
579 $ilBench->startDbBench($query);
581 $num_affected_rows = $this->pdo->exec($query);
583 $ilBench->stopDbBench();
585 }
catch (PDOException
$e) {
589 return (
int) $num_affected_rows;
594 $res = $statement->
fetch(PDO::FETCH_ASSOC);
595 if (
$res ===
null ||
$res ===
false) {
596 $statement->closeCursor();
609 public function quote($value, ?
string $type =
null): string
611 if ($value ===
null) {
615 $pdo_type = PDO::PARAM_STR;
623 if ($value === $this->now()) {
626 $value = (string) $value;
629 return (
string) (
int) $value;
631 $pdo_type = PDO::PARAM_INT;
632 $value = (string) $value;
636 $value = (string) $value;
637 $pdo_type = PDO::PARAM_STR;
641 return $this->pdo->quote((
string) $value, $pdo_type);
646 foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
647 $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
648 $idx_fields = array_keys($def[
'fields']);
650 if ($idx_fields === $fields) {
658 public function addIndex(
string $table_name, array $fields,
string $index_name =
'',
bool $fulltext =
false): bool
660 $this->field_definition->checkIndexName($index_name);
662 $definition_fields = [];
663 foreach ($fields as
$f) {
664 $definition_fields[
$f] = [];
667 'fields' => $definition_fields,
671 $this->manager->createIndex($table_name, $this->constraintName($table_name, $index_name), $definition);
672 } elseif ($this->supportsFulltext()) {
673 $this->addFulltextIndex($table_name, $fields, $index_name);
680 public function addFulltextIndex(
string $table_name, array $fields,
string $name =
'in'): bool
690 $i_name = $this->constraintName($a_table, $a_name) .
"_idx";
691 $this->query(
"ALTER TABLE $a_table DROP FULLTEXT $i_name");
700 $set = $this->query(
"SHOW INDEX FROM " . $a_table);
701 while ($rec = $this->fetchAssoc($set)) {
702 if ($rec[
"Key_name"] === $a_name && $rec[
"Index_type"] ===
"FULLTEXT") {
712 return sprintf(FieldDefinition::INDEX_FORMAT, preg_replace(
'/[^a-z0-9_\$]/i',
'_', $index_name_base));
717 return sprintf(FieldDefinition::SEQUENCE_FORMAT, preg_replace(
'/[^a-z0-9_\$.]/i',
'_', $table_name));
726 return $a_constraint;
736 return $this->db_type;
741 $this->db_type = $type;
749 public static function getReservedWords(): array
757 $fd =
$ilDB->getFieldDefinition();
759 return $fd->getReservedMysql();
769 $lock = $this->manager->getQueryUtils()->lock($tables);
770 $this->pdo->exec($lock);
779 $this->pdo->exec($this->manager->getQueryUtils()->unlock());
782 public function in(
string $field, array $values,
bool $negate =
false,
string $type =
""): string
784 return $this->manager->getQueryUtils()->in($field, $values, $negate, $type);
793 if (count($types) !== count($values)) {
794 throw new ilDatabaseException(
"ilDB::queryF: Types and values must be arrays of same size. ($query)");
797 foreach ($types as $k => $t) {
798 $quoted_values[] = $this->quote($values[$k], $t);
800 $query = vsprintf($query, $quoted_values);
802 return $this->query($query);
811 if (count($types) !== count($values)) {
812 throw new ilDatabaseException(
"ilDB::manipulateF: types and values must be arrays of same size. ($query)");
815 foreach ($types as $k => $t) {
816 $quoted_values[] = $this->quote($values[$k], $t);
818 $query = vsprintf($query, $quoted_values);
820 return $this->manipulate($query);
831 public function setLimit(
int $limit,
int $offset = 0): void
833 $this->limit = $limit;
834 $this->offset = $offset;
840 public function like(
string $column,
string $type,
string $value =
"?",
bool $case_insensitive =
true): string
842 return $this->manager->getQueryUtils()->like($column, $type, $value, $case_insensitive);
848 public function now(): string
850 return $this->manager->getQueryUtils()->now();
853 public function replace(
string $table, array $primary_keys, array $other_columns):
int
855 $a_columns = array_merge($primary_keys, $other_columns);
861 foreach ($a_columns as $k => $col) {
862 $fields[] = $this->quoteIdentifier($k);
863 $placeholders[] =
"%s";
864 $placeholders2[] =
":$k";
868 if ($col[0] ===
'integer' && !is_null($col[1])) {
869 $col[1] = (
int) $col[1];
875 $q =
"REPLACE INTO " . $table .
" (" . implode(
",", $fields) .
") VALUES (" . implode(
",", $placeholders) .
")";
877 return $this->manipulateF(
$q, $types, $values);
883 public function equals(
string $columns, $value,
string $type,
bool $emptyOrNull =
false): string
885 if (!$emptyOrNull || $value !=
"") {
886 return $columns .
" = " . $this->quote($value, $type);
889 return "(" . $columns .
" = '' OR $columns IS NULL)";
904 return $this->dbname;
909 $this->dbname = $dbname;
914 return $this->charset;
919 $this->charset = $charset;
924 return $this->username;
929 $this->username = $username;
934 return $this->password;
939 $this->password = $password;
954 $this->setUsername($user);
959 $this->setPort($port);
964 $this->setPassword($password);
969 $this->setHost($host);
972 public function upper(
string $expression): string
974 return " UPPER(" . $expression .
") ";
977 public function lower(
string $expression): string
979 return " LOWER(" . $expression .
") ";
982 public function substr(
string $a_exp,
int $a_pos = 1,
int $a_len = -1): string
986 $lenstr =
", " . $a_len;
988 return " SUBSTR(" . $a_exp .
", " . $a_pos . $lenstr .
") ";
1003 $this->pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $a_status);
1026 return $this->details->supportsTransactions();
1031 return match ($feature) {
1032 self::FEATURE_TRANSACTIONS => $this->supportsTransactions(),
1033 self::FEATURE_FULLTEXT => $this->supportsFulltext(),
1034 self::FEATURE_SLAVE => $this->supportsSlave(),
1044 return $this->manager->listTables();
1052 return match ($module) {
1055 default =>
throw new LogicException(
'module "' . $module .
'" not available'),
1061 return $this->field_definition->getAllowedAttributes();
1066 return in_array($sequence, $this->listSequences(),
true);
1071 return $this->manager->listSequences();
1074 public function concat(array $values,
bool $allow_null =
true): string
1076 return $this->manager->getQueryUtils()->concat($values, $allow_null);
1081 if ($this->limit !==
null && $this->offset !==
null) {
1082 $query .=
' LIMIT ' . $this->offset .
', ' . $this->limit;
1083 $this->limit =
null;
1084 $this->offset =
null;
1092 public function locate(
string $needle,
string $string,
int $start_pos = 1): string
1094 return $this->manager->getQueryUtils()->locate($needle, $string, $start_pos);
1102 $def = $this->reverse->getTableFieldDefinition($table, $column);
1105 $best_alt = $analyzer->getBestDefinitionAlternative($def);
1106 $def = $def[$best_alt];
1107 unset($def[
"nativetype"], $def[
"mdb2type"]);
1110 $ilDBPdoFieldDefinition = $this->field_definition;
1112 $type = $attributes[
"type"] ?? $def[
"type"];
1114 foreach (array_keys($def) as $k) {
1115 if ($k !==
"type" && !$ilDBPdoFieldDefinition->isAllowedAttribute($k, $type)) {
1119 $check_array = $def;
1120 foreach ($attributes as $k => $v) {
1121 $check_array[$k] = $v;
1123 if (!$this->checkColumnDefinition($check_array,
true)) {
1124 throw new ilDatabaseException(
"ilDB Error: modifyTableColumn(" . $table .
", " . $column .
")");
1127 foreach ($attributes as
$a => $v) {
1131 $attributes[
"definition"] = $def;
1135 $column => $attributes,
1139 return $this->manager->alterTable($table, $changes,
false);
1144 $a_st->closeCursor();
1154 $this->checkTableName($new_name);
1156 throw new ilDatabaseException(
"ilDB Error: renameTable(" . $name .
"," . $new_name .
")<br />" .
$e->getMessage(),
$e->getCode());
1159 $this->manager->alterTable($name, [
"name" => $new_name],
false);
1160 if ($this->sequenceExists($name)) {
1161 $this->manager->alterTable(
1162 $this->getSequenceName($name),
1163 [
"name" => $this->getSequenceName($new_name)],
1180 return $this->field_definition->checkTableName($a_name);
1194 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1198 return $this->pdo->beginTransaction();
1206 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1210 return $this->pdo->commit();
1218 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1222 return $this->pdo->rollBack();
1225 public function dropIndex(
string $a_table,
string $a_name =
"i1"): bool
1227 return $this->manager->dropIndex($a_table, $a_name);
1232 $this->storage_engine = $storage_engine;
1237 return $this->storage_engine;
1240 public function queryCol(
string $query,
int $type = PDO::FETCH_ASSOC,
int $colnum = 0): array
1242 $type = match ($type) {
1245 default => PDO::FETCH_ASSOC,
1248 return $this->pdo->query($query, PDO::FETCH_ASSOC)->fetchAll(PDO::FETCH_COLUMN, $colnum);
1253 ?array $types =
null,
1256 $type = match ($fetchmode) {
1259 default => PDO::FETCH_ASSOC,
1262 return $this->pdo->query($query, $type)->fetch();
1267 return $this->pdo->query(
'SELECT VERSION()')->fetchColumn();
1270 public function escape(
string $value,
bool $escape_wildcards =
false): string
1286 $engines = $this->queryCol(
'SHOW ENGINES');
1287 if (!in_array($engine, $engines,
true)) {
1291 $tables = $this->listTables();
1292 array_walk($tables,
function (
string $table_name) use (&$errors, $engine):
void {
1294 $this->pdo->exec(
"ALTER TABLE $table_name ENGINE=$engine");
1295 if ($this->sequenceExists($table_name)) {
1296 $this->pdo->exec(
"ALTER TABLE {$table_name}_seq ENGINE=$engine");
1298 }
catch (Exception
$e) {
1299 $errors[$table_name] =
$e->getMessage();
1310 foreach ($this->manager->listTables() as $table_name) {
1311 if (!$this->migrateTableCollation($table_name, $collation)) {
1312 $errors[] = $table_name;
1335 $fd = $this->getFieldDefinition();
1337 return $fd->checkIndexName($name);
1347 $manager = $this->manager;
1350 if (!$this->checkIndexName($name)) {
1351 throw new ilDatabaseException(
"ilDB Error: addUniqueConstraint(" . $table .
"," . $name .
")");
1354 $fields_corrected = [];
1355 foreach ($fields as
$f) {
1356 $fields_corrected[
$f] = [];
1360 'fields' => $fields_corrected,
1363 return $manager->
createConstraint($table, $this->constraintName($table, $name), $definition);
1368 return $this->manager->dropConstraint($table, $this->constraintName($table, $name),
false);
1374 $cons = $analyzer->getConstraintsInformation($table);
1375 foreach ($cons as
$c) {
1376 if (
$c[
"type"] ===
"unique" && count($fields) === count(
$c[
"fields"])) {
1378 foreach ($fields as
$f) {
1379 if (!isset(
$c[
"fields"][
$f])) {
1384 return $this->dropUniqueConstraint($table,
$c[
'name']);
1394 return (
int) $this->pdo->lastInsertId();
1399 return $this->details->atomQuery($this);
1405 $cons = $analyzer->getConstraintsInformation($table);
1406 foreach ($cons as
$c) {
1407 if (
$c[
"type"] ===
"unique" && count($fields) === count(
$c[
"fields"])) {
1409 foreach ($fields as
$f) {
1410 if (!isset(
$c[
"fields"][
$f])) {
1425 return $this->manager->dropConstraint($table_name,
"PRIMARY",
true);
1430 foreach (
$data as $set) {
1431 $this->execute($stmt, $set);
1438 return "FROM_UNIXTIME(" . $expr .
")";
1443 return "UNIX_TIMESTAMP()";
1451 $d = $this->fetchObject($this->query(
"SELECT VERSION() AS version"));
1453 if (
$d !==
null &&
$d->version) {
1461 if (!$this->doesCollationSupportMB4Strings()) {
1462 $query_replaced = preg_replace(
1463 '/[\x{10000}-\x{10FFFF}]/u',
1467 if (!empty($query_replaced)) {
1468 return $query_replaced;
1490 public function groupConcat(
string $a_field_name,
string $a_seperator =
",", ?
string $a_order =
null): string
1492 return $this->manager->getQueryUtils()->groupConcat($a_field_name, $a_seperator, $a_order);
1495 public function cast(
string $a_field_name,
string $a_dest_type): string
1497 return $a_field_name;
1501 string $foreign_key_name,
1504 array $reference_field_names,
1505 string $reference_table,
1509 return $this->manager->addForeignKey($foreign_key_name, $field_names, $table_name, $reference_field_names, $reference_table, $on_update, $on_delete);
1514 return $this->manager->dropForeignKey($foreign_key_name, $table_name);
1519 return $this->manager->foreignKeyExists($foreign_key_name, $table_name);
1529 $constraints = $this->manager->listTableConstraints($table_name);
1531 if (in_array(
'primary', $constraints)) {
1532 $definitions = $this->reverse->getTableConstraintDefinition($table_name,
'primary');
1533 $primary_fields = array_keys($definitions[
'fields']);
1534 sort($primary_fields);
1537 return $primary_fields === $fields;
1545 $collation_split = explode(
"_", $collation);
1546 $character = $collation_split[0] ??
'utf8mb4';
1547 $collate = $collation;
1548 $q =
"ALTER TABLE {$this->quoteIdentifier($table_name)} CONVERT TO CHARACTER SET {$character} COLLATE {$collate};";
1550 $this->pdo->exec(
$q);
1551 }
catch (PDOException) {
1560 $this->pdo->exec(
"ALTER TABLE {$table_name} ENGINE={$engine}");
1561 if ($this->sequenceExists($table_name)) {
1562 $this->pdo->exec(
"ALTER TABLE {$table_name}_seq ENGINE={$engine}");
1564 }
catch (PDOException
$e) {
This class gives all kind of DB information using the database manager and reverse module.
const MYSQL_ENGINE_INNODB
const MYSQL_COLLATION_UTF8MB4
Class ilDBPdoMySQLFieldDefinition.
renameTable(string $name, string $new_name)
fetchAll(ilDBStatement $statement, int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
addForeignKey(string $foreign_key_name, array $field_names, string $table_name, array $reference_field_names, string $reference_table, ?ForeignKeyConstraints $on_update=null, ?ForeignKeyConstraints $on_delete=null)
setUsername(string $username)
dropUniqueConstraintByFields(string $table, array $fields)
checkColumnName(string $a_name)
setLimit(int $limit, int $offset=0)
Set the Limit for the next Query.
createTable(string $table_name, array $fields, bool $drop_table=false, bool $ignore_erros=false)
in(string $field, array $values, bool $negate=false, string $type="")
tableExists(string $table_name)
manipulateF(string $query, array $types, array $values)
dropTable(string $table_name, bool $error_if_not_existing=true)
sanitizeMB4StringIfNotSupported(string $query)
isFulltextIndex(string $a_table, string $a_name)
Is index a fulltext index?
numRows(ilDBStatement $statement)
setStorageEngine(string $storage_engine)
escapePattern(string $text)
free(ilDBStatement $a_st)
connect(bool $return_false_for_error=false)
insert(string $table_name, array $values)
fromUnixtime(string $expr, bool $to_text=true)
groupConcat(string $a_field_name, string $a_seperator=",", ?string $a_order=null)
enableResultBuffering(bool $a_status)
checkIndexName(string $name)
dropIndex(string $a_table, string $a_name="i1")
addPrimaryKey(string $table_name, array $primary_keys)
dropForeignKey(string $foreign_key_name, string $table_name)
substr(string $a_exp, int $a_pos=1, int $a_len=-1)
queryF(string $query, array $types, array $values)
migrateTableToEngine(string $table_name, string $engine=ilDBConstants::MYSQL_ENGINE_INNODB)
supportsEngineMigration()
getPrimaryKeyIdentifier()
executeMultiple(ilDBStatement $stmt, array $data)
checkTableName(string $a_name)
setDBPassword(string $password)
sequenceExists(string $sequence)
escape(string $value, bool $escape_wildcards=false)
getServerVersion(bool $native=false)
modifyTableColumn(string $table, string $column, array $attributes)
addUniqueConstraint(string $table, array $fields, string $name="con")
migrateAllTablesToCollation(string $collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
setCharset(string $charset)
dropFulltextIndex(string $a_table, string $a_name)
Drop fulltext index.
dropUniqueConstraint(string $table, string $name="con")
addIndex(string $table_name, array $fields, string $index_name='', bool $fulltext=false)
getSequenceName(string $table_name)
createSequence(string $table_name, int $start=1)
dropPrimaryKey(string $table_name)
supportsCollationMigration()
appendLimit(string $query)
prepareManip(string $query, ?array $types=null)
loadModule(string $module)
queryCol(string $query, int $type=PDO::FETCH_ASSOC, int $colnum=0)
setDbname(string $dbname)
indexExistsByFields(string $table_name, array $fields)
concat(array $values, bool $allow_null=true)
renameTableColumn(string $table_name, string $column_old_name, string $column_new_name)
equals(string $columns, $value, string $type, bool $emptyOrNull=false)
lockTables(array $tables)
checkColumn(string $a_col, array $a_def)
migrateAllTablesToEngine(string $engine=ilDBConstants::MYSQL_ENGINE_INNODB)
addFulltextIndex(string $table_name, array $fields, string $name='in')
primaryExistsByFields(string $table_name, array $fields)
prepare(string $query, ?array $types=null, ?array $result_types=null)
Prepare a query (SELECT) statement to be used with execute.
__construct(private readonly Details $details)
like(string $column, string $type, string $value="?", bool $case_insensitive=true)
dropIndexByFields(string $table_name, array $fields)
quoteIdentifier(string $identifier, bool $check_option=false)
doesCollationSupportMB4Strings()
const FEATURE_TRANSACTIONS
dropTableColumn(string $table_name, string $column_name)
createDatabase(string $a_name, string $a_charset="utf8", string $a_collation="")
getIndexName(string $index_name_base)
manipulate(string $query)
addTableColumn(string $table_name, string $column_name, array $attributes)
constraintName(string $a_table, string $a_constraint)
Determine contraint name by table name and constraint name.
migrateTableCollation(string $table_name, string $collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
fetchAssoc(ilDBStatement $statement)
checkTableColumns(array $a_cols)
replace(string $table, array $primary_keys, array $other_columns)
Replace into method.
locate(string $needle, string $string, int $start_pos=1)
checkColumnDefinition(array $a_def, bool $a_modify_mode=false)
upper(string $expression)
foreignKeyExists(string $foreign_key_name, string $table_name)
dropSequence(string $table_name)
uniqueConstraintExists(string $table, array $fields)
nextId(string $table_name)
cast(string $a_field_name, string $a_dest_type)
fetchObject(ilDBStatement $query_result)
update(string $table_name, array $columns, array $where)
@description $where MUST contain existing columns only.
static isReservedWord(string $a_word)
supports(string $feature)
execute(ilDBStatement $stmt, array $data=[])
setPassword(string $password)
setFieldDefinition(FieldDefinition $field_definition)
tableColumnExists(string $table_name, string $column_name)
queryRow(string $query, ?array $types=null, int $fetchmode=ilDBConstants::FETCHMODE_DEFAULT)
initFromIniFile(?ilIniFile $ini=null)
FieldDefinition $field_definition
quote($value, ?string $type=null)
lower(string $expression)
Class ilDatabaseException.
INIFile Parser Early access in init proceess! Avoid further dependencies like logging or other servic...
Class ilPDOStatement is a Wrapper Class for PDOStatement.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilAtomQuery Use ilAtomQuery to fire Database-Actions which have to be done without beeing i...
createConstraint(string $table, string $name, array $definition)
execute(?array $a_data=null)
fetch(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
if(!file_exists('../ilias.ini.php'))