ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ilDBPdo Class Reference
+ Inheritance diagram for ilDBPdo:
+ Collaboration diagram for ilDBPdo:

Public Member Functions

 __construct (private readonly Details $details)
 
 connect (bool $return_false_for_error=false)
 
 initHelpers ()
 
 getFieldDefinition ()
 
 setFieldDefinition (FieldDefinition $field_definition)
 
 createDatabase (string $a_name, string $a_charset="utf8", string $a_collation="")
 
 getLastErrorCode ()
 
 initFromIniFile (?ilIniFile $ini=null)
 
 generateDSN ()
 
 quoteIdentifier (string $identifier, bool $check_option=false)
 
 nextId (string $table_name)
 
 createTable (string $table_name, array $fields, bool $drop_table=false, bool $ignore_erros=false)
 
 checkColumnName (string $a_name)
 
 addPrimaryKey (string $table_name, array $primary_keys)
 
 dropIndexByFields (string $table_name, array $fields)
 
 getPrimaryKeyIdentifier ()
 
 createSequence (string $table_name, int $start=1)
 
 tableExists (string $table_name)
 
 tableColumnExists (string $table_name, string $column_name)
 
 addTableColumn (string $table_name, string $column_name, array $attributes)
 
 dropTable (string $table_name, bool $error_if_not_existing=true)
 
 query (string $query)
 
 fetchAll (ilDBStatement $statement, int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
 
 dropSequence (string $table_name)
 
 dropTableColumn (string $table_name, string $column_name)
 
 renameTableColumn (string $table_name, string $column_old_name, string $column_new_name)
 
 insert (string $table_name, array $values)
 
 fetchObject (ilDBStatement $query_result)
 
 update (string $table_name, array $columns, array $where)
 @description $where MUST contain existing columns only. More...
 
 manipulate (string $query)
 
 fetchAssoc (ilDBStatement $statement)
 
 numRows (ilDBStatement $statement)
 
 quote ($value, ?string $type=null)
 
 indexExistsByFields (string $table_name, array $fields)
 
 addIndex (string $table_name, array $fields, string $index_name='', bool $fulltext=false)
 
 addFulltextIndex (string $table_name, array $fields, string $name='in')
 
 dropFulltextIndex (string $a_table, string $a_name)
 Drop fulltext index. More...
 
 isFulltextIndex (string $a_table, string $a_name)
 Is index a fulltext index? More...
 
 getIndexName (string $index_name_base)
 
 getSequenceName (string $table_name)
 
 constraintName (string $a_table, string $a_constraint)
 Determine contraint name by table name and constraint name. More...
 
 getDSN ()
 Get DSN. More...
 
 getDBType ()
 Get DSN. More...
 
 setDBType (string $type)
 
 lockTables (array $tables)
 
 unlockTables ()
 
 in (string $field, array $values, bool $negate=false, string $type="")
 
 queryF (string $query, array $types, array $values)
 
 manipulateF (string $query, array $types, array $values)
 
 useSlave (bool $bool)
 
 setLimit (int $limit, int $offset=0)
 Set the Limit for the next Query. More...
 
 like (string $column, string $type, string $value="?", bool $case_insensitive=true)
 
 now ()
 
 replace (string $table, array $primary_keys, array $other_columns)
 Replace into method. More...
 
 equals (string $columns, $value, string $type, bool $emptyOrNull=false)
 
 getHost ()
 
 setHost (string $host)
 
 getDbname ()
 
 setDbname (string $dbname)
 
 getCharset ()
 
 setCharset (string $charset)
 
 getUsername ()
 
 setUsername (string $username)
 
 getPassword ()
 
 setPassword (string $password)
 
 getPort ()
 
 setPort (int $port)
 
 setDBUser (string $user)
 
 setDBPort (int $port)
 
 setDBPassword (string $password)
 
 setDBHost (string $host)
 
 upper (string $expression)
 
 lower (string $expression)
 
 substr (string $a_exp, int $a_pos=1, int $a_len=-1)
 
 prepareManip (string $query, ?array $types=null)
 
 prepare (string $query, ?array $types=null, ?array $result_types=null)
 Prepare a query (SELECT) statement to be used with execute. More...
 
 enableResultBuffering (bool $a_status)
 
 execute (ilDBStatement $stmt, array $data=[])
 
 supportsSlave ()
 
 supportsFulltext ()
 
 supportsTransactions ()
 
 supports (string $feature)
 
 listTables ()
 
 loadModule (string $module)
 
 getAllowedAttributes ()
 
 sequenceExists (string $sequence)
 
 listSequences ()
 
 concat (array $values, bool $allow_null=true)
 
 locate (string $needle, string $string, int $start_pos=1)
 
 modifyTableColumn (string $table, string $column, array $attributes)
 
 free (ilDBStatement $a_st)
 
 renameTable (string $name, string $new_name)
 
 checkTableName (string $a_name)
 
 beginTransaction ()
 
 commit ()
 
 rollback ()
 
 dropIndex (string $a_table, string $a_name="i1")
 
 setStorageEngine (string $storage_engine)
 
 getStorageEngine ()
 
 queryCol (string $query, int $type=PDO::FETCH_ASSOC, int $colnum=0)
 
 queryRow (string $query, ?array $types=null, int $fetchmode=ilDBConstants::FETCHMODE_DEFAULT)
 
 getServerVersion (bool $native=false)
 
 escape (string $value, bool $escape_wildcards=false)
 
 escapePattern (string $text)
 
 migrateAllTablesToEngine (string $engine=ilDBConstants::MYSQL_ENGINE_INNODB)
 
 migrateAllTablesToCollation (string $collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
 
 supportsCollationMigration ()
 
 supportsEngineMigration ()
 
 checkIndexName (string $name)
 
 addUniqueConstraint (string $table, array $fields, string $name="con")
 
 dropUniqueConstraint (string $table, string $name="con")
 
 dropUniqueConstraintByFields (string $table, array $fields)
 
 getLastInsertId ()
 
 buildAtomQuery ()
 
 uniqueConstraintExists (string $table, array $fields)
 
 dropPrimaryKey (string $table_name)
 
 executeMultiple (ilDBStatement $stmt, array $data)
 
 fromUnixtime (string $expr, bool $to_text=true)
 
 unixTimestamp ()
 
 getDBVersion ()
 
 sanitizeMB4StringIfNotSupported (string $query)
 
 doesCollationSupportMB4Strings ()
 
 groupConcat (string $a_field_name, string $a_seperator=",", ?string $a_order=null)
 
 cast (string $a_field_name, string $a_dest_type)
 
 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)
 
 dropForeignKey (string $foreign_key_name, string $table_name)
 
 foreignKeyExists (string $foreign_key_name, string $table_name)
 
 buildIntegrityAnalyser ()
 
 primaryExistsByFields (string $table_name, array $fields)
 
 migrateTableCollation (string $table_name, string $collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
 
 migrateTableToEngine (string $table_name, string $engine=ilDBConstants::MYSQL_ENGINE_INNODB)
 
 getFieldDefinition ()
 
 getIndexName (string $index_name_base)
 
- Public Member Functions inherited from ilDBInterface
 doesCollationSupportMB4Strings ()
 
 sanitizeMB4StringIfNotSupported (string $query)
 
 initFromIniFile (?ilIniFile $ini=null)
 
 connect (bool $return_false_on_error=false)
 
 nextId (string $table_name)
 
 createTable (string $table_name, array $fields, bool $drop_table=false, bool $ignore_erros=false)
 
 addPrimaryKey (string $table_name, array $primary_keys)
 
 createSequence (string $table_name, int $start=1)
 
 getSequenceName (string $table_name)
 
 tableExists (string $table_name)
 
 tableColumnExists (string $table_name, string $column_name)
 
 addTableColumn (string $table_name, string $column_name, array $attributes)
 
 dropTable (string $table_name, bool $error_if_not_existing=true)
 
 renameTable (string $old_name, string $new_name)
 
 query (string $query)
 Run a (read-only) Query on the database. More...
 
 fetchAll (ilDBStatement $statement, int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
 
 dropSequence (string $table_name)
 
 dropTableColumn (string $table_name, string $column_name)
 
 renameTableColumn (string $table_name, string $column_old_name, string $column_new_name)
 
 insert (string $table_name, array $values)
 
 fetchObject (ilDBStatement $query_result)
 
 update (string $table_name, array $values, array $where)
 @description $where MUST contain existing columns only. More...
 
 manipulate (string $query)
 Run a (write) Query on the database. More...
 
 fetchAssoc (ilDBStatement $statement)
 
 numRows (ilDBStatement $statement)
 
 quote ($value, string $type)
 
 addIndex (string $table_name, array $fields, string $index_name='', bool $fulltext=false)
 
 indexExistsByFields (string $table_name, array $fields)
 
 getDSN ()
 Get DSN. More...
 
 getDBType ()
 Get DSN. More...
 
 lockTables (array $tables)
 Abstraction of lock table. More...
 
 unlockTables ()
 Unlock tables locked by previous lock table calls. More...
 
 in (string $field, array $values, bool $negate=false, string $type="")
 
 queryF (string $query, array $types, array $values)
 
 manipulateF (string $query, array $types, array $values)
 
 useSlave (bool $bool)
 
 setLimit (int $limit, int $offset=0)
 
 like (string $column, string $type, string $value="?", bool $case_insensitive=true)
 Generate a like subquery. More...
 
 now ()
 
 replace (string $table, array $primary_keys, array $other_columns)
 Replace into method. More...
 
 equals (string $columns, $value, string $type, bool $emptyOrNull=false)
 
 setDBUser (string $user)
 
 setDBPort (int $port)
 
 setDBPassword (string $password)
 
 setDBHost (string $host)
 
 upper (string $expression)
 
 lower (string $expression)
 
 substr (string $expression)
 
 prepare (string $a_query, ?array $a_types=null, ?array $a_result_types=null)
 Prepare a query (SELECT) statement to be used with execute. More...
 
 prepareManip (string $a_query, ?array $a_types=null)
 
 enableResultBuffering (bool $a_status)
 
 execute (ilDBStatement $stmt, array $data=[])
 
 sequenceExists (string $sequence)
 
 listSequences ()
 
 supports (string $feature)
 
 supportsFulltext ()
 
 supportsSlave ()
 
 supportsTransactions ()
 
 listTables ()
 
 loadModule (string $module)
 
 getAllowedAttributes ()
 
 concat (array $values, bool $allow_null=true)
 
 locate (string $needle, string $string, int $start_pos=1)
 
 quoteIdentifier (string $identifier, bool $check_option=false)
 
 modifyTableColumn (string $table, string $column, array $attributes)
 
 free (ilDBStatement $a_st)
 
 checkTableName (string $a_name)
 
 beginTransaction ()
 
 commit ()
 
 rollback ()
 
 constraintName (string $a_table, string $a_constraint)
 
 dropIndex (string $a_table, string $a_name="i1")
 
 createDatabase (string $a_name, string $a_charset="utf8", string $a_collation="")
 
 dropIndexByFields (string $table_name, array $afields)
 
 getPrimaryKeyIdentifier ()
 
 addFulltextIndex (string $table_name, array $afields, string $a_name='in')
 
 dropFulltextIndex (string $a_table, string $a_name)
 
 isFulltextIndex (string $a_table, string $a_name)
 
 setStorageEngine (string $storage_engine)
 
 getStorageEngine ()
 
 buildAtomQuery ()
 
 groupConcat (string $a_field_name, string $a_seperator=",", ?string $a_order=null)
 
 cast (string $a_field_name, string $a_dest_type)
 
 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)
 
 dropForeignKey (string $foreign_key_name, string $table_name)
 
 foreignKeyExists (string $foreign_key_name, string $table_name)
 
 buildIntegrityAnalyser ()
 
 primaryExistsByFields (string $table_name, array $fields)
 
 getServerVersion (bool $native=false)
 
 queryCol (string $query, int $type=ilDBConstants::FETCHMODE_DEFAULT, int $colnum=0)
 
 queryRow (string $query, ?array $types=null, int $fetchmode=ilDBConstants::FETCHMODE_DEFAULT)
 
 escape (string $value, bool $escape_wildcards=false)
 
 escapePattern (string $text)
 
 migrateTableToEngine (string $table_name, string $engine=ilDBConstants::MYSQL_ENGINE_INNODB)
 
 migrateAllTablesToEngine (string $engine=ilDBConstants::MYSQL_ENGINE_INNODB)
 
 supportsEngineMigration ()
 
 migrateTableCollation (string $table_name, string $collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
 
 migrateAllTablesToCollation (string $collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
 
 supportsCollationMigration ()
 
 addUniqueConstraint (string $table, array $fields, string $name="con")
 
 dropUniqueConstraint (string $table, string $name="con")
 
 dropUniqueConstraintByFields (string $table, array $fields)
 
 checkIndexName (string $name)
 
 getLastInsertId ()
 
 uniqueConstraintExists (string $table, array $fields)
 
 dropPrimaryKey (string $table_name)
 
 executeMultiple (ilDBStatement $stmt, array $data)
 
 fromUnixtime (string $expr, bool $to_text=true)
 
 unixTimestamp ()
 
 getDBVersion ()
 returns the Version of the Database (e.g. More...
 

Static Public Member Functions

static isReservedWord (string $a_word)
 
- Static Public Member Functions inherited from ilDBInterface
static getReservedWords ()
 Get reserved words. More...
 
static isReservedWord (string $a_word)
 

Data Fields

array $options = []
 
const FEATURE_TRANSACTIONS = 'transactions'
 
const FEATURE_FULLTEXT = 'fulltext'
 
const FEATURE_SLAVE = 'slave'
 

Protected Member Functions

 getAttributes ()
 

Private Member Functions

 checkTableColumns (array $a_cols)
 
 checkColumn (string $a_col, array $a_def)
 
 checkColumnDefinition (array $a_def, bool $a_modify_mode=false)
 
 appendLimit (string $query)
 

Private Attributes

string $host = ''
 
string $dbname = ''
 
string $charset = 'utf8'
 
string $username = ''
 
string $password = ''
 
int $port = 3306
 
PDO $pdo = null
 
ilDBManager $manager
 
ilDBReverse $reverse
 
int $limit = null
 
int $offset = null
 
string $storage_engine = 'InnoDB'
 
string $dsn = ''
 
string $db_type = ''
 
int $error_code = 0
 
FieldDefinition $field_definition = null
 
const SESSION_MODES
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilDBPdo::__construct ( private readonly Details  $details)

Definition at line 66 of file ilDBPdo.php.

67 {
68 }

Member Function Documentation

◆ addForeignKey()

ilDBPdo::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 
)
Parameters
string[]$field_names
string[]$reference_field_names

Implements ilDBInterface.

Definition at line 1500 of file ilDBPdo.php.

1508 : bool {
1509 return $this->manager->addForeignKey($foreign_key_name, $field_names, $table_name, $reference_field_names, $reference_table, $on_update, $on_delete);
1510 }

◆ addFulltextIndex()

ilDBPdo::addFulltextIndex ( string  $table_name,
array  $fields,
string  $name = 'in' 
)

Implements ilDBInterface.

Definition at line 680 of file ilDBPdo.php.

680 : bool
681 {
682 return false;
683 }

◆ addIndex()

ilDBPdo::addIndex ( string  $table_name,
array  $fields,
string  $index_name = '',
bool  $fulltext = false 
)

Implements ilDBInterface.

Definition at line 658 of file ilDBPdo.php.

658 : bool
659 {
660 $this->field_definition->checkIndexName($index_name);
661
662 $definition_fields = [];
663 foreach ($fields as $f) {
664 $definition_fields[$f] = [];
665 }
666 $definition = [
667 'fields' => $definition_fields,
668 ];
669
670 if (!$fulltext) {
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);
674 // TODO
675 }
676
677 return true;
678 }
supportsFulltext()
Definition: ilDBPdo.php:1019
addFulltextIndex(string $table_name, array $fields, string $name='in')
Definition: ilDBPdo.php:680
constraintName(string $a_table, string $a_constraint)
Determine contraint name by table name and constraint name.
Definition: ilDBPdo.php:724

References Vendor\Package\$f.

◆ addPrimaryKey()

ilDBPdo::addPrimaryKey ( string  $table_name,
array  $primary_keys 
)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 262 of file ilDBPdo.php.

262 : bool
263 {
264 $fields = [];
265 foreach ($primary_keys as $f) {
266 $fields[$f] = [];
267 }
268 $definition = [
269 'primary' => true,
270 'fields' => $fields,
271 ];
272 $this->manager->createConstraint(
273 $table_name,
274 $this->constraintName($table_name, $this->getPrimaryKeyIdentifier()),
275 $definition
276 );
277
278 return true;
279 }
getPrimaryKeyIdentifier()
Definition: ilDBPdo.php:298

References Vendor\Package\$f.

◆ addTableColumn()

ilDBPdo::addTableColumn ( string  $table_name,
string  $column_name,
array  $attributes 
)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 327 of file ilDBPdo.php.

327 : bool
328 {
329 if (!$this->checkColumnName($column_name)) {
330 throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
331 }
332 if (!$this->checkColumnDefinition($attributes)) {
333 throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
334 }
335
336 $changes = [
337 "add" => [
338 $column_name => $attributes,
339 ],
340 ];
341
342 return $this->manager->alterTable($table_name, $changes, false);
343 }
checkColumnName(string $a_name)
Definition: ilDBPdo.php:254
checkColumnDefinition(array $a_def, bool $a_modify_mode=false)
Definition: ilDBPdo.php:249
Class ilDatabaseException.

◆ addUniqueConstraint()

ilDBPdo::addUniqueConstraint ( string  $table,
array  $fields,
string  $name = "con" 
)
Exceptions

ilDatabaseException

Implements ilDBPdoInterface.

Definition at line 1345 of file ilDBPdo.php.

1345 : bool
1346 {
1348
1349 // check index name
1350 if (!$this->checkIndexName($name)) {
1351 throw new ilDatabaseException("ilDB Error: addUniqueConstraint(" . $table . "," . $name . ")");
1352 }
1353
1354 $fields_corrected = [];
1355 foreach ($fields as $f) {
1356 $fields_corrected[$f] = [];
1357 }
1358 $definition = [
1359 'unique' => true,
1360 'fields' => $fields_corrected,
1361 ];
1362
1363 return $manager->createConstraint($table, $this->constraintName($table, $name), $definition);
1364 }
checkIndexName(string $name)
Definition: ilDBPdo.php:1333
ilDBManager $manager
Definition: ilDBPdo.php:46
createConstraint(string $table, string $name, array $definition)

References Vendor\Package\$f, and ilDBManager\createConstraint().

+ Here is the call graph for this function:

◆ appendLimit()

ilDBPdo::appendLimit ( string  $query)
private

Definition at line 1079 of file ilDBPdo.php.

1079 : string
1080 {
1081 if ($this->limit !== null && $this->offset !== null) {
1082 $query .= ' LIMIT ' . $this->offset . ', ' . $this->limit;
1083 $this->limit = null;
1084 $this->offset = null;
1085
1086 return $query;
1087 }
1088
1089 return $query;
1090 }
int $limit
Definition: ilDBPdo.php:48

◆ beginTransaction()

ilDBPdo::beginTransaction ( )
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 1192 of file ilDBPdo.php.

1192 : bool
1193 {
1194 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1195 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1196 }
1197
1198 return $this->pdo->beginTransaction();
1199 }
supports(string $feature)
Definition: ilDBPdo.php:1029

◆ buildAtomQuery()

ilDBPdo::buildAtomQuery ( )

Implements ilDBInterface.

Definition at line 1397 of file ilDBPdo.php.

1397 : ilAtomQuery
1398 {
1399 return $this->details->atomQuery($this);
1400 }
Interface ilAtomQuery Use ilAtomQuery to fire Database-Actions which have to be done without beeing i...
Definition: ilAtomQuery.php:28

◆ buildIntegrityAnalyser()

ilDBPdo::buildIntegrityAnalyser ( )

Implements ilDBInterface.

Definition at line 1522 of file ilDBPdo.php.

1522 : Integrity
1523 {
1524 return new Integrity($this);
1525 }

◆ cast()

ilDBPdo::cast ( string  $a_field_name,
string  $a_dest_type 
)

Implements ilDBInterface.

Definition at line 1495 of file ilDBPdo.php.

1495 : string
1496 {
1497 return $a_field_name;
1498 }

◆ checkColumn()

ilDBPdo::checkColumn ( string  $a_col,
array  $a_def 
)
private

Definition at line 241 of file ilDBPdo.php.

241 : bool
242 {
243 if (!$this->checkColumnName($a_col)) {
244 return false;
245 }
246 return $this->checkColumnDefinition($a_def);
247 }

◆ checkColumnDefinition()

ilDBPdo::checkColumnDefinition ( array  $a_def,
bool  $a_modify_mode = false 
)
private

Definition at line 249 of file ilDBPdo.php.

249 : bool
250 {
251 return $this->field_definition->checkColumnDefinition($a_def);
252 }

◆ checkColumnName()

ilDBPdo::checkColumnName ( string  $a_name)

Definition at line 254 of file ilDBPdo.php.

254 : bool
255 {
256 return $this->field_definition->checkColumnName($a_name);
257 }

◆ checkIndexName()

ilDBPdo::checkIndexName ( string  $name)
Exceptions

ilDatabaseException

Implements ilDBPdoInterface.

Definition at line 1333 of file ilDBPdo.php.

1333 : bool
1334 {
1335 $fd = $this->getFieldDefinition();
1336 if ($fd !== null) {
1337 return $fd->checkIndexName($name);
1338 }
1339 return false;
1340 }
getFieldDefinition()
Definition: ilDBPdo.php:110

◆ checkTableColumns()

ilDBPdo::checkTableColumns ( array  $a_cols)
private

Definition at line 230 of file ilDBPdo.php.

230 : bool
231 {
232 foreach ($a_cols as $col => $def) {
233 if (!$this->checkColumn($col, $def)) {
234 return false;
235 }
236 }
237
238 return true;
239 }
checkColumn(string $a_col, array $a_def)
Definition: ilDBPdo.php:241

◆ checkTableName()

ilDBPdo::checkTableName ( string  $a_name)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 1178 of file ilDBPdo.php.

1178 : bool
1179 {
1180 return $this->field_definition->checkTableName($a_name);
1181 }

◆ commit()

ilDBPdo::commit ( )
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 1204 of file ilDBPdo.php.

1204 : bool
1205 {
1206 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1207 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1208 }
1209
1210 return $this->pdo->commit();
1211 }

◆ concat()

ilDBPdo::concat ( array  $values,
bool  $allow_null = true 
)

Implements ilDBInterface.

Definition at line 1074 of file ilDBPdo.php.

1074 : string
1075 {
1076 return $this->manager->getQueryUtils()->concat($values, $allow_null);
1077 }

◆ connect()

ilDBPdo::connect ( bool  $return_false_for_error = false)
Exceptions

Exception

Implements ilDBInterface.

Definition at line 73 of file ilDBPdo.php.

73 : ?bool
74 {
75 $this->generateDSN();
76 try {
77 $options = $this->getAttributes();
78 $this->pdo = new PDO($this->getDSN(), $this->getUsername(), $this->getPassword(), $options);
79 $this->pdo->exec("SET SESSION sql_mode = '" . implode(",", self::SESSION_MODES) . "';");
80 $this->manager = new ilDBPdoManager($this->pdo, $this);
81 $this->reverse = new ilDBPdoReverse($this->pdo, $this);
82 $this->field_definition = new ilDBPdoMySQLFieldDefinition($this);
83 } catch (Exception $e) {
84 $this->error_code = $e->getCode();
85 if ($return_false_for_error) {
86 return false;
87 }
88 throw $e;
89 }
90
91 return ($this->pdo->errorCode() === PDO::ERR_NONE);
92 }
Class ilDBPdoManager.
Class ilDBPdoMySQLFieldDefinition.
Class ilDBPdoReverse.
getPassword()
Definition: ilDBPdo.php:932
array $options
Definition: ilDBPdo.php:33
getAttributes()
Definition: ilDBPdo.php:101
getUsername()
Definition: ilDBPdo.php:922
generateDSN()
Definition: ilDBPdo.php:167
getDSN()
Get DSN.
Definition: ilDBPdo.php:729

References Vendor\Package\$e, generateDSN(), getAttributes(), getDSN(), getPassword(), and getUsername().

Referenced by createDatabase().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ constraintName()

ilDBPdo::constraintName ( string  $a_table,
string  $a_constraint 
)

Determine contraint name by table name and constraint name.

In MySQL these are "unique" per table

Implements ilDBInterface.

Definition at line 724 of file ilDBPdo.php.

724 : string
725 {
726 return $a_constraint;
727 }

◆ createDatabase()

ilDBPdo::createDatabase ( string  $a_name,
string  $a_charset = "utf8",
string  $a_collation = "" 
)

Implements ilDBInterface.

Definition at line 120 of file ilDBPdo.php.

120 : bool
121 {
122 $this->setDbname('');
123 $this->generateDSN();
124 $this->connect(true);
125 try {
126 $this->query($this->manager->getQueryUtils()->createDatabase($a_name, $a_charset, $a_collation));
127 return true;
128 } catch (PDOException) {
129 return false;
130 }
131 }
connect(bool $return_false_for_error=false)
Definition: ilDBPdo.php:73
query(string $query)
Definition: ilDBPdo.php:373
setDbname(string $dbname)
Definition: ilDBPdo.php:907

References connect(), generateDSN(), query(), and setDbname().

+ Here is the call graph for this function:

◆ createSequence()

ilDBPdo::createSequence ( string  $table_name,
int  $start = 1 
)

Implements ilDBInterface.

Definition at line 303 of file ilDBPdo.php.

303 : bool
304 {
305 $this->manager->createSequence($table_name, $start);
306 return true;
307 }

◆ createTable()

ilDBPdo::createTable ( string  $table_name,
array  $fields,
bool  $drop_table = false,
bool  $ignore_erros = false 
)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 207 of file ilDBPdo.php.

212 : bool {
213 // check table name
214 if (!$ignore_erros && !$this->checkTableName($table_name)) {
215 throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
216 }
217
218 // check definition array
219 if (!$ignore_erros && !$this->checkTableColumns($fields)) {
220 throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
221 }
222
223 if ($drop_table) {
224 $this->dropTable($table_name, false);
225 }
226
227 return $this->manager->createTable($table_name, $fields, []);
228 }
dropTable(string $table_name, bool $error_if_not_existing=true)
Definition: ilDBPdo.php:348
checkTableName(string $a_name)
Definition: ilDBPdo.php:1178
checkTableColumns(array $a_cols)
Definition: ilDBPdo.php:230

◆ doesCollationSupportMB4Strings()

ilDBPdo::doesCollationSupportMB4Strings ( )

Implements ilDBInterface.

Definition at line 1476 of file ilDBPdo.php.

1476 : bool
1477 {
1478 // Currently ILIAS does not support utf8mb4, after that ilDB could check like this:
1479 // static $supported;
1480 // if (!isset($supported)) {
1481 // $q = "SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = %s;";
1482 // $res = $this->queryF($q, ['text'], [$this->getDbname()]);
1483 // $data = $this->fetchObject($res);
1484 // $supported = ($data->default_character_set_name === 'utf8mb4');
1485 // }
1486
1487 return false;
1488 }

◆ dropForeignKey()

ilDBPdo::dropForeignKey ( string  $foreign_key_name,
string  $table_name 
)

Implements ilDBInterface.

Definition at line 1512 of file ilDBPdo.php.

1512 : bool
1513 {
1514 return $this->manager->dropForeignKey($foreign_key_name, $table_name);
1515 }

◆ dropFulltextIndex()

ilDBPdo::dropFulltextIndex ( string  $a_table,
string  $a_name 
)

Drop fulltext index.

Implements ilDBInterface.

Definition at line 688 of file ilDBPdo.php.

688 : bool
689 {
690 $i_name = $this->constraintName($a_table, $a_name) . "_idx";
691 $this->query("ALTER TABLE $a_table DROP FULLTEXT $i_name");
692 return true;
693 }

◆ dropIndex()

ilDBPdo::dropIndex ( string  $a_table,
string  $a_name = "i1" 
)

Implements ilDBInterface.

Definition at line 1225 of file ilDBPdo.php.

1225 : bool
1226 {
1227 return $this->manager->dropIndex($a_table, $a_name);
1228 }

◆ dropIndexByFields()

ilDBPdo::dropIndexByFields ( string  $table_name,
array  $fields 
)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 284 of file ilDBPdo.php.

284 : bool
285 {
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']);
289
290 if ($idx_fields === $fields) {
291 return $this->dropIndex($table_name, $idx_name);
292 }
293 }
294
295 return false;
296 }
dropIndex(string $a_table, string $a_name="i1")
Definition: ilDBPdo.php:1225

◆ dropPrimaryKey()

ilDBPdo::dropPrimaryKey ( string  $table_name)

Implements ilDBPdoInterface.

Definition at line 1423 of file ilDBPdo.php.

1423 : bool
1424 {
1425 return $this->manager->dropConstraint($table_name, "PRIMARY", true);
1426 }

◆ dropSequence()

ilDBPdo::dropSequence ( string  $table_name)

Implements ilDBInterface.

Definition at line 412 of file ilDBPdo.php.

412 : bool
413 {
414 $this->manager->dropSequence($table_name);
415 return true;
416 }

◆ dropTable()

ilDBPdo::dropTable ( string  $table_name,
bool  $error_if_not_existing = true 
)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 348 of file ilDBPdo.php.

348 : bool
349 {
350 $tables = $this->manager->listTables();
351 $table_exists = in_array($table_name, $tables);
352 if (!$table_exists && $error_if_not_existing) {
353 throw new ilDatabaseException("Table $table_name does not exist");
354 }
355
356 // drop sequence
357 $sequences = $this->manager->listSequences();
358 if (in_array($table_name, $sequences)) {
359 $this->manager->dropSequence($table_name);
360 }
361
362 // drop table
363 if ($table_exists) {
364 $this->manager->dropTable($table_name);
365 }
366
367 return true;
368 }

◆ dropTableColumn()

ilDBPdo::dropTableColumn ( string  $table_name,
string  $column_name 
)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 421 of file ilDBPdo.php.

421 : bool
422 {
423 $changes = [
424 "remove" => [
425 $column_name => [],
426 ],
427 ];
428
429 return $this->manager->alterTable($table_name, $changes, false);
430 }

◆ dropUniqueConstraint()

ilDBPdo::dropUniqueConstraint ( string  $table,
string  $name = "con" 
)

Implements ilDBPdoInterface.

Definition at line 1366 of file ilDBPdo.php.

1366 : bool
1367 {
1368 return $this->manager->dropConstraint($table, $this->constraintName($table, $name), false);
1369 }

◆ dropUniqueConstraintByFields()

ilDBPdo::dropUniqueConstraintByFields ( string  $table,
array  $fields 
)

Implements ilDBPdoInterface.

Definition at line 1371 of file ilDBPdo.php.

1371 : bool
1372 {
1373 $analyzer = new ilDBAnalyzer();
1374 $cons = $analyzer->getConstraintsInformation($table);
1375 foreach ($cons as $c) {
1376 if ($c["type"] === "unique" && count($fields) === count($c["fields"])) {
1377 $all_in = true;
1378 foreach ($fields as $f) {
1379 if (!isset($c["fields"][$f])) {
1380 $all_in = false;
1381 }
1382 }
1383 if ($all_in) {
1384 return $this->dropUniqueConstraint($table, $c['name']);
1385 }
1386 }
1387 }
1388
1389 return false;
1390 }
This class gives all kind of DB information using the database manager and reverse module.
dropUniqueConstraint(string $table, string $name="con")
Definition: ilDBPdo.php:1366
$c
Definition: deliver.php:25

References $c, and Vendor\Package\$f.

◆ enableResultBuffering()

ilDBPdo::enableResultBuffering ( bool  $a_status)

Implements ilDBInterface.

Definition at line 1001 of file ilDBPdo.php.

1001 : void
1002 {
1003 $this->pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $a_status);
1004 }

◆ equals()

ilDBPdo::equals ( string  $columns,
  $value,
string  $type,
bool  $emptyOrNull = false 
)
Parameters
mixed$value

Implements ilDBInterface.

Definition at line 883 of file ilDBPdo.php.

883 : string
884 {
885 if (!$emptyOrNull || $value != "") {
886 return $columns . " = " . $this->quote($value, $type);
887 }
888
889 return "(" . $columns . " = '' OR $columns IS NULL)";
890 }
quote($value, ?string $type=null)
Definition: ilDBPdo.php:609

◆ escape()

ilDBPdo::escape ( string  $value,
bool  $escape_wildcards = false 
)

Implements ilDBPdoInterface.

Definition at line 1270 of file ilDBPdo.php.

1270 : string
1271 {
1272 return $value;
1273 }

◆ escapePattern()

ilDBPdo::escapePattern ( string  $text)

Implements ilDBPdoInterface.

Definition at line 1275 of file ilDBPdo.php.

1275 : string
1276 {
1277 return $text;
1278 }
$text
Definition: xapiexit.php:21

References $text.

◆ execute()

ilDBPdo::execute ( ilDBStatement  $stmt,
array  $data = [] 
)
Exceptions
ilDatabaseException

Implements ilDBInterface.

Definition at line 1009 of file ilDBPdo.php.

1010 {
1011 return $stmt->execute($data);
1012 }
Interface ilDBStatement.
execute(?array $a_data=null)

References $data, and ilDBStatement\execute().

+ Here is the call graph for this function:

◆ executeMultiple()

ilDBPdo::executeMultiple ( ilDBStatement  $stmt,
array  $data 
)
Parameters
ilDBStatement[]$stmt
Returns
string[]

Implements ilDBPdoInterface.

Definition at line 1428 of file ilDBPdo.php.

1428 : array
1429 {
1430 foreach ($data as $set) {
1431 $this->execute($stmt, $set);
1432 }
1433 return [];
1434 }
execute(ilDBStatement $stmt, array $data=[])
Definition: ilDBPdo.php:1009

References $data.

◆ fetchAll()

ilDBPdo::fetchAll ( ilDBStatement  $statement,
int  $fetch_mode = ilDBConstants::FETCHMODE_ASSOC 
)

Implements ilDBInterface.

Definition at line 402 of file ilDBPdo.php.

402 : array
403 {
404 $return = [];
405 while ($data = $statement->fetch($fetch_mode)) {
406 $return[] = $data;
407 }
408
409 return $return;
410 }
fetch(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)

References $data, and ilDBStatement\fetch().

+ Here is the call graph for this function:

◆ fetchAssoc()

ilDBPdo::fetchAssoc ( ilDBStatement  $statement)

Implements ilDBInterface.

Definition at line 592 of file ilDBPdo.php.

592 : ?array
593 {
594 $res = $statement->fetch(PDO::FETCH_ASSOC);
595 if ($res === null || $res === false) {
596 $statement->closeCursor();
597
598 return null;
599 }
600
601 return $res;
602 }
$res
Definition: ltiservices.php:69

References $res, and ilDBStatement\fetch().

+ Here is the call graph for this function:

◆ fetchObject()

ilDBPdo::fetchObject ( ilDBStatement  $query_result)

Implements ilDBInterface.

Definition at line 479 of file ilDBPdo.php.

479 : ?stdClass
480 {
481 $res = $query_result->fetchObject();
482 if ($res === null) {
483 $query_result->closeCursor();
484
485 return null;
486 }
487
488 return $res;
489 }

References $res, and ilDBStatement\fetchObject().

+ Here is the call graph for this function:

◆ foreignKeyExists()

ilDBPdo::foreignKeyExists ( string  $foreign_key_name,
string  $table_name 
)

Implements ilDBInterface.

Definition at line 1517 of file ilDBPdo.php.

1517 : bool
1518 {
1519 return $this->manager->foreignKeyExists($foreign_key_name, $table_name);
1520 }

◆ free()

ilDBPdo::free ( ilDBStatement  $a_st)

Implements ilDBInterface.

Definition at line 1142 of file ilDBPdo.php.

1142 : void
1143 {
1144 $a_st->closeCursor();
1145 }

◆ fromUnixtime()

ilDBPdo::fromUnixtime ( string  $expr,
bool  $to_text = true 
)

Implements ilDBPdoInterface.

Definition at line 1436 of file ilDBPdo.php.

1436 : string
1437 {
1438 return "FROM_UNIXTIME(" . $expr . ")";
1439 }

◆ generateDSN()

ilDBPdo::generateDSN ( )

Definition at line 167 of file ilDBPdo.php.

167 : void
168 {
169 $port = $this->getPort() !== 0 ? ";port=" . $this->getPort() : "";
170 $dbname = $this->getDbname() !== '' ? ';dbname=' . $this->getDbname() : '';
171 $host = $this->getHost();
172 $charset = ';charset=' . $this->getCharset();
173 $this->dsn = 'mysql:host=' . $host . $port . $dbname . $charset;
174 }
string $dbname
Definition: ilDBPdo.php:40
getPort()
Definition: ilDBPdo.php:942
getDbname()
Definition: ilDBPdo.php:902
string $host
Definition: ilDBPdo.php:39
string $charset
Definition: ilDBPdo.php:41
getHost()
Definition: ilDBPdo.php:892
int $port
Definition: ilDBPdo.php:44
getCharset()
Definition: ilDBPdo.php:912

References $charset, $dbname, $host, $port, getCharset(), getDbname(), getHost(), and getPort().

Referenced by connect(), createDatabase(), and initFromIniFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAllowedAttributes()

ilDBPdo::getAllowedAttributes ( )
Returns
string[]

Implements ilDBInterface.

Definition at line 1059 of file ilDBPdo.php.

1059 : array
1060 {
1061 return $this->field_definition->getAllowedAttributes();
1062 }

◆ getAttributes()

ilDBPdo::getAttributes ( )
protected

Definition at line 101 of file ilDBPdo.php.

101 : array
102 {
103 return [
104 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
105 PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
106 PDO::ATTR_TIMEOUT => 300 * 60,
107 ];
108 }

Referenced by connect().

+ Here is the caller graph for this function:

◆ getCharset()

ilDBPdo::getCharset ( )

Definition at line 912 of file ilDBPdo.php.

912 : string
913 {
914 return $this->charset;
915 }

Referenced by generateDSN().

+ Here is the caller graph for this function:

◆ getDbname()

ilDBPdo::getDbname ( )

Definition at line 902 of file ilDBPdo.php.

902 : string
903 {
904 return $this->dbname;
905 }

Referenced by generateDSN().

+ Here is the caller graph for this function:

◆ getDBType()

ilDBPdo::getDBType ( )

Get DSN.

This must be overwritten in DBMS specific class.

Implements ilDBInterface.

Definition at line 734 of file ilDBPdo.php.

734 : string
735 {
736 return $this->db_type;
737 }
string $db_type
Definition: ilDBPdo.php:52

◆ getDBVersion()

ilDBPdo::getDBVersion ( )
Exceptions
ilDatabaseException

Implements ilDBPdoInterface.

Definition at line 1449 of file ilDBPdo.php.

1449 : string
1450 {
1451 $d = $this->fetchObject($this->query("SELECT VERSION() AS version"));
1452
1453 if ($d !== null && $d->version) {
1454 return $d->version;
1455 }
1456 return 'Unknown';
1457 }
fetchObject(ilDBStatement $query_result)
Definition: ilDBPdo.php:479

References Vendor\Package\$d.

◆ getDSN()

ilDBPdo::getDSN ( )

Get DSN.

This must be overwritten in DBMS specific class.

Implements ilDBInterface.

Definition at line 729 of file ilDBPdo.php.

729 : string
730 {
731 return $this->dsn;
732 }
string $dsn
Definition: ilDBPdo.php:51

Referenced by connect().

+ Here is the caller graph for this function:

◆ getFieldDefinition()

ilDBPdo::getFieldDefinition ( )

Implements ILIAS\Database\PDO\Internal.

Definition at line 110 of file ilDBPdo.php.

111 {
113 }
FieldDefinition $field_definition
Definition: ilDBPdo.php:54

References $field_definition.

◆ getHost()

ilDBPdo::getHost ( )

Definition at line 892 of file ilDBPdo.php.

892 : string
893 {
894 return $this->host;
895 }

Referenced by generateDSN().

+ Here is the caller graph for this function:

◆ getIndexName()

ilDBPdo::getIndexName ( string  $index_name_base)

Implements ILIAS\Database\PDO\Internal.

Definition at line 710 of file ilDBPdo.php.

710 : string
711 {
712 return sprintf(FieldDefinition::INDEX_FORMAT, preg_replace('/[^a-z0-9_\$]/i', '_', $index_name_base));
713 }

◆ getLastErrorCode()

ilDBPdo::getLastErrorCode ( )
Returns
string|int|null

Definition at line 136 of file ilDBPdo.php.

137 {
138 if ($this->pdo instanceof PDO) {
139 return $this->pdo->errorCode();
140 }
141
142 return $this->error_code;
143 }
int $error_code
Definition: ilDBPdo.php:53

References $error_code.

◆ getLastInsertId()

ilDBPdo::getLastInsertId ( )

Implements ilDBPdoInterface.

Definition at line 1392 of file ilDBPdo.php.

1392 : int
1393 {
1394 return (int) $this->pdo->lastInsertId();
1395 }

◆ getPassword()

ilDBPdo::getPassword ( )

Definition at line 932 of file ilDBPdo.php.

932 : string
933 {
934 return $this->password;
935 }
string $password
Definition: ilDBPdo.php:43

Referenced by connect().

+ Here is the caller graph for this function:

◆ getPort()

ilDBPdo::getPort ( )

Definition at line 942 of file ilDBPdo.php.

942 : int
943 {
944 return $this->port;
945 }

Referenced by generateDSN().

+ Here is the caller graph for this function:

◆ getPrimaryKeyIdentifier()

ilDBPdo::getPrimaryKeyIdentifier ( )

Implements ilDBInterface.

Definition at line 298 of file ilDBPdo.php.

298 : string
299 {
300 return "PRIMARY";
301 }

◆ getSequenceName()

ilDBPdo::getSequenceName ( string  $table_name)

Implements ilDBInterface.

Definition at line 715 of file ilDBPdo.php.

715 : string
716 {
717 return sprintf(FieldDefinition::SEQUENCE_FORMAT, preg_replace('/[^a-z0-9_\$.]/i', '_', $table_name));
718 }

Referenced by nextId().

+ Here is the caller graph for this function:

◆ getServerVersion()

ilDBPdo::getServerVersion ( bool  $native = false)

Implements ilDBPdoInterface.

Definition at line 1265 of file ilDBPdo.php.

1265 : int
1266 {
1267 return $this->pdo->query('SELECT VERSION()')->fetchColumn();
1268 }

◆ getStorageEngine()

ilDBPdo::getStorageEngine ( )

Implements ilDBInterface.

Definition at line 1235 of file ilDBPdo.php.

1235 : string
1236 {
1237 return $this->storage_engine;
1238 }
string $storage_engine
Definition: ilDBPdo.php:50

◆ getUsername()

ilDBPdo::getUsername ( )

Definition at line 922 of file ilDBPdo.php.

922 : string
923 {
924 return $this->username;
925 }
string $username
Definition: ilDBPdo.php:42

Referenced by connect().

+ Here is the caller graph for this function:

◆ groupConcat()

ilDBPdo::groupConcat ( string  $a_field_name,
string  $a_seperator = ",",
?string  $a_order = null 
)

Implements ilDBInterface.

Definition at line 1490 of file ilDBPdo.php.

1490 : string
1491 {
1492 return $this->manager->getQueryUtils()->groupConcat($a_field_name, $a_seperator, $a_order);
1493 }

◆ in()

ilDBPdo::in ( string  $field,
array  $values,
bool  $negate = false,
string  $type = "" 
)

Implements ilDBInterface.

Definition at line 782 of file ilDBPdo.php.

782 : string
783 {
784 return $this->manager->getQueryUtils()->in($field, $values, $negate, $type);
785 }

◆ indexExistsByFields()

ilDBPdo::indexExistsByFields ( string  $table_name,
array  $fields 
)

Implements ilDBInterface.

Definition at line 644 of file ilDBPdo.php.

644 : bool
645 {
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']);
649
650 if ($idx_fields === $fields) {
651 return true;
652 }
653 }
654
655 return false;
656 }

◆ initFromIniFile()

ilDBPdo::initFromIniFile ( ?ilIniFile  $ini = null)

Implements ilDBInterface.

Definition at line 145 of file ilDBPdo.php.

145 : void
146 {
147 global $DIC;
148
149 if ($ini instanceof ilIniFile) {
150 $clientIniFile = $ini;
151 } elseif ($DIC->offsetExists('ilClientIniFile')) {
152 $clientIniFile = $DIC['ilClientIniFile'];
153 } else {
154 throw new InvalidArgumentException('$tmpClientIniFile is not an instance of ilIniFile');
155 }
156
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"));
163
164 $this->generateDSN();
165 }
setUsername(string $username)
Definition: ilDBPdo.php:927
setPort(int $port)
Definition: ilDBPdo.php:947
setHost(string $host)
Definition: ilDBPdo.php:897
setDBType(string $type)
Definition: ilDBPdo.php:739
setPassword(string $password)
Definition: ilDBPdo.php:937
INIFile Parser Early access in init proceess! Avoid further dependencies like logging or other servic...
$ini
Definition: raiseError.php:20
global $DIC
Definition: shib_login.php:26

References $DIC, $ini, generateDSN(), setDbname(), setDBType(), setHost(), setPassword(), setPort(), and setUsername().

+ Here is the call graph for this function:

◆ initHelpers()

ilDBPdo::initHelpers ( )
Deprecated:

Definition at line 97 of file ilDBPdo.php.

97 : void
98 {
99 }

◆ insert()

ilDBPdo::insert ( string  $table_name,
array  $values 
)
Returns
int The number of rows affected by the manipulation

Implements ilDBInterface.

Definition at line 462 of file ilDBPdo.php.

462 : int
463 {
464 $real = [];
465 $fields = [];
466 foreach ($values as $key => $val) {
467 $real[] = $this->quote($val[1], $val[0]);
468 $fields[] = $this->quoteIdentifier($key);
469 }
470 $values_string = implode(",", $real);
471 $fields_string = implode(",", $fields);
472 $query = "INSERT INTO " . $this->quoteIdentifier($table_name) . " (" . $fields_string . ") VALUES (" . $values_string . ")";
473
474 $query = $this->sanitizeMB4StringIfNotSupported($query);
475
476 return (int) $this->pdo->exec($query);
477 }
sanitizeMB4StringIfNotSupported(string $query)
Definition: ilDBPdo.php:1459
quoteIdentifier(string $identifier, bool $check_option=false)
Definition: ilDBPdo.php:176

◆ isFulltextIndex()

ilDBPdo::isFulltextIndex ( string  $a_table,
string  $a_name 
)

Is index a fulltext index?

Implements ilDBInterface.

Definition at line 698 of file ilDBPdo.php.

698 : bool
699 {
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") {
703 return true;
704 }
705 }
706
707 return false;
708 }
fetchAssoc(ilDBStatement $statement)
Definition: ilDBPdo.php:592

◆ isReservedWord()

static ilDBPdo::isReservedWord ( string  $a_word)
static

Implements ilDBInterface.

Definition at line 1183 of file ilDBPdo.php.

1183 : bool
1184 {
1185 global $DIC;
1186 return (new ilDBPdoMySQLFieldDefinition($DIC->database()))->isReserved($a_word);
1187 }

References $DIC.

◆ like()

ilDBPdo::like ( string  $column,
string  $type,
string  $value = "?",
bool  $case_insensitive = true 
)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 840 of file ilDBPdo.php.

840 : string
841 {
842 return $this->manager->getQueryUtils()->like($column, $type, $value, $case_insensitive);
843 }

◆ listSequences()

ilDBPdo::listSequences ( )
Returns
string[]

Implements ilDBInterface.

Definition at line 1069 of file ilDBPdo.php.

1069 : array
1070 {
1071 return $this->manager->listSequences();
1072 }

◆ listTables()

ilDBPdo::listTables ( )
Returns
int[]|string[]

Implements ilDBInterface.

Definition at line 1042 of file ilDBPdo.php.

1042 : array
1043 {
1044 return $this->manager->listTables();
1045 }

◆ loadModule()

ilDBPdo::loadModule ( string  $module)
Returns
\ilDBManager|\ilDBReverse

Implements ilDBInterface.

Definition at line 1050 of file ilDBPdo.php.

1051 {
1052 return match ($module) {
1055 default => throw new LogicException('module "' . $module . '" not available'),
1056 };
1057 }
const MODULE_MANAGER
const MODULE_REVERSE
ilDBReverse $reverse
Definition: ilDBPdo.php:47

References ilDBConstants\MODULE_MANAGER, and ilDBConstants\MODULE_REVERSE.

◆ locate()

ilDBPdo::locate ( string  $needle,
string  $string,
int  $start_pos = 1 
)

Implements ilDBInterface.

Definition at line 1092 of file ilDBPdo.php.

1092 : string
1093 {
1094 return $this->manager->getQueryUtils()->locate($needle, $string, $start_pos);
1095 }

◆ lockTables()

ilDBPdo::lockTables ( array  $tables)
Deprecated:
Use ilAtomQuery instead

Implements ilDBInterface.

Definition at line 767 of file ilDBPdo.php.

767 : void
768 {
769 $lock = $this->manager->getQueryUtils()->lock($tables);
770 $this->pdo->exec($lock);
771 }

◆ lower()

ilDBPdo::lower ( string  $expression)

Implements ilDBInterface.

Definition at line 977 of file ilDBPdo.php.

977 : string
978 {
979 return " LOWER(" . $expression . ") ";
980 }

◆ manipulate()

ilDBPdo::manipulate ( string  $query)
Exceptions
ilDatabaseException

Implements ilDBInterface.

Definition at line 572 of file ilDBPdo.php.

572 : int
573 {
574 global $DIC;
575 $ilBench = $DIC['ilBench'] ?? null;
576 try {
577 $query = $this->sanitizeMB4StringIfNotSupported($query);
578 if ($ilBench instanceof ilBenchmark) {
579 $ilBench->startDbBench($query);
580 }
581 $num_affected_rows = $this->pdo->exec($query);
582 if ($ilBench instanceof ilBenchmark) {
583 $ilBench->stopDbBench();
584 }
585 } catch (PDOException $e) {
586 throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query, (int) $e->getCode());
587 }
588
589 return (int) $num_affected_rows;
590 }
Class ilBenchmark.

References $DIC, and Vendor\Package\$e.

◆ manipulateF()

ilDBPdo::manipulateF ( string  $query,
array  $types,
array  $values 
)
Parameters
string[]$types
Exceptions
ilDatabaseException

Implements ilDBInterface.

Definition at line 809 of file ilDBPdo.php.

809 : int
810 {
811 if (count($types) !== count($values)) {
812 throw new ilDatabaseException("ilDB::manipulateF: types and values must be arrays of same size. ($query)");
813 }
814 $quoted_values = [];
815 foreach ($types as $k => $t) {
816 $quoted_values[] = $this->quote($values[$k], $t);
817 }
818 $query = vsprintf($query, $quoted_values);
819
820 return $this->manipulate($query);
821 }
manipulate(string $query)
Definition: ilDBPdo.php:572

◆ migrateAllTablesToCollation()

ilDBPdo::migrateAllTablesToCollation ( string  $collation = ilDBConstants::MYSQL_COLLATION_UTF8MB4)
Returns
array of failed tables

Implements ilDBPdoInterface.

Definition at line 1307 of file ilDBPdo.php.

1307 : array
1308 {
1309 $errors = [];
1310 foreach ($this->manager->listTables() as $table_name) {
1311 if (!$this->migrateTableCollation($table_name, $collation)) {
1312 $errors[] = $table_name;
1313 }
1314 }
1315
1316 return $errors;
1317 }
migrateTableCollation(string $table_name, string $collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
Definition: ilDBPdo.php:1543

◆ migrateAllTablesToEngine()

ilDBPdo::migrateAllTablesToEngine ( string  $engine = ilDBConstants::MYSQL_ENGINE_INNODB)
Returns
array<int|string, string>

Implements ilDBPdoInterface.

Definition at line 1284 of file ilDBPdo.php.

1284 : array
1285 {
1286 $engines = $this->queryCol('SHOW ENGINES');
1287 if (!in_array($engine, $engines, true)) {
1288 return [];
1289 }
1290 $errors = [];
1291 $tables = $this->listTables();
1292 array_walk($tables, function (string $table_name) use (&$errors, $engine): void {
1293 try {
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");
1297 }
1298 } catch (Exception $e) {
1299 $errors[$table_name] = $e->getMessage();
1300 }
1301 });
1302
1303 return $errors;
1304 }
listTables()
Definition: ilDBPdo.php:1042
sequenceExists(string $sequence)
Definition: ilDBPdo.php:1064
queryCol(string $query, int $type=PDO::FETCH_ASSOC, int $colnum=0)
Definition: ilDBPdo.php:1240

References Vendor\Package\$e.

◆ migrateTableCollation()

ilDBPdo::migrateTableCollation ( string  $table_name,
string  $collation = ilDBConstants::MYSQL_COLLATION_UTF8MB4 
)

Implements ilDBPdoInterface.

Definition at line 1543 of file ilDBPdo.php.

1543 : bool
1544 {
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};";
1549 try {
1550 $this->pdo->exec($q);
1551 } catch (PDOException) {
1552 return false;
1553 }
1554 return true;
1555 }
$q
Definition: shib_logout.php:25

References $q.

◆ migrateTableToEngine()

ilDBPdo::migrateTableToEngine ( string  $table_name,
string  $engine = ilDBConstants::MYSQL_ENGINE_INNODB 
)

Implements ilDBPdoInterface.

Definition at line 1557 of file ilDBPdo.php.

1557 : void
1558 {
1559 try {
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}");
1563 }
1564 } catch (PDOException $e) {
1565 throw new ilDatabaseException($e->getMessage(), $e->getCode());
1566 }
1567 }

References Vendor\Package\$e.

◆ modifyTableColumn()

ilDBPdo::modifyTableColumn ( string  $table,
string  $column,
array  $attributes 
)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 1100 of file ilDBPdo.php.

1100 : bool
1101 {
1102 $def = $this->reverse->getTableFieldDefinition($table, $column);
1103
1104 $analyzer = new ilDBAnalyzer($this);
1105 $best_alt = $analyzer->getBestDefinitionAlternative($def);
1106 $def = $def[$best_alt];
1107 unset($def["nativetype"], $def["mdb2type"]);
1108
1109 // check attributes
1110 $ilDBPdoFieldDefinition = $this->field_definition;
1111
1112 $type = $attributes["type"] ?? $def["type"];
1113
1114 foreach (array_keys($def) as $k) {
1115 if ($k !== "type" && !$ilDBPdoFieldDefinition->isAllowedAttribute($k, $type)) {
1116 unset($def[$k]);
1117 }
1118 }
1119 $check_array = $def;
1120 foreach ($attributes as $k => $v) {
1121 $check_array[$k] = $v;
1122 }
1123 if (!$this->checkColumnDefinition($check_array, true)) {
1124 throw new ilDatabaseException("ilDB Error: modifyTableColumn(" . $table . ", " . $column . ")");
1125 }
1126
1127 foreach ($attributes as $a => $v) {
1128 $def[$a] = $v;
1129 }
1130
1131 $attributes["definition"] = $def;
1132
1133 $changes = [
1134 "change" => [
1135 $column => $attributes,
1136 ],
1137 ];
1138
1139 return $this->manager->alterTable($table, $changes, false);
1140 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a.

◆ nextId()

ilDBPdo::nextId ( string  $table_name)

Implements ilDBInterface.

Definition at line 182 of file ilDBPdo.php.

182 : int
183 {
184 $sequence_name = $this->quoteIdentifier($this->getSequenceName($table_name), true);
185 $seqcol_name = $this->quoteIdentifier('sequence');
186 $query = "INSERT INTO $sequence_name ($seqcol_name) VALUES (NULL)";
187 try {
188 $this->pdo->exec($query);
189 } catch (PDOException) {
190 // no such table check
191 }
192
193 $result = $this->query('SELECT LAST_INSERT_ID() AS next');
194 $value = $result->fetchObject()->next;
195
196 if (is_numeric($value)) {
197 $query = "DELETE FROM $sequence_name WHERE $seqcol_name < $value";
198 $this->pdo->exec($query);
199 }
200
201 return (int) $value;
202 }
getSequenceName(string $table_name)
Definition: ilDBPdo.php:715

References getSequenceName(), query(), and quoteIdentifier().

+ Here is the call graph for this function:

◆ now()

ilDBPdo::now ( )
Returns
string the now statement

Implements ilDBInterface.

Definition at line 848 of file ilDBPdo.php.

848 : string
849 {
850 return $this->manager->getQueryUtils()->now();
851 }

◆ numRows()

ilDBPdo::numRows ( ilDBStatement  $statement)

Implements ilDBInterface.

Definition at line 604 of file ilDBPdo.php.

604 : int
605 {
606 return $statement->rowCount();
607 }

References ilDBStatement\rowCount().

+ Here is the call graph for this function:

◆ prepare()

ilDBPdo::prepare ( string  $a_query,
?array  $a_types = null,
?array  $a_result_types = null 
)

Prepare a query (SELECT) statement to be used with execute.

Implements ilDBInterface.

Definition at line 996 of file ilDBPdo.php.

997 {
998 return new ilPDOStatement($this->pdo->prepare($query));
999 }
Class ilPDOStatement is a Wrapper Class for PDOStatement.

◆ prepareManip()

ilDBPdo::prepareManip ( string  $query,
?array  $types = null 
)

Implements ilDBInterface.

Definition at line 991 of file ilDBPdo.php.

992 {
993 return new ilPDOStatement($this->pdo->prepare($query));
994 }

◆ primaryExistsByFields()

ilDBPdo::primaryExistsByFields ( string  $table_name,
array  $fields 
)

Implements ilDBInterface.

Definition at line 1527 of file ilDBPdo.php.

1527 : bool
1528 {
1529 $constraints = $this->manager->listTableConstraints($table_name);
1530
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);
1535 sort($fields);
1536
1537 return $primary_fields === $fields;
1538 }
1539 return false;
1540 }

References ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

+ Here is the call graph for this function:

◆ query()

ilDBPdo::query ( string  $query)
Exceptions
ilDatabaseException

Implements ilDBInterface.

Definition at line 373 of file ilDBPdo.php.

374 {
375 global $DIC;
376 $ilBench = $DIC['ilBench'] ?? null;
377
378 $query = $this->appendLimit($query);
379
380 try {
381 if ($ilBench instanceof ilBenchmark) {
382 $ilBench->startDbBench($query);
383 }
384 $res = $this->pdo->query($query);
385 if ($ilBench instanceof ilBenchmark) {
386 $ilBench->stopDbBench();
387 }
388 } catch (PDOException $e) {
389 throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query, (int) $e->getCode());
390 }
391
392 $err = $this->pdo->errorCode();
393 if ($err !== PDO::ERR_NONE) {
394 $info = $this->pdo->errorInfo();
395 $info_message = $info[2];
396 throw new ilDatabaseException($info_message . ' QUERY: ' . $query);
397 }
398
399 return new ilPDOStatement($res);
400 }
appendLimit(string $query)
Definition: ilDBPdo.php:1079
$info
Definition: entry_point.php:21

References $DIC, Vendor\Package\$e, $info, and $res.

Referenced by createDatabase(), and nextId().

+ Here is the caller graph for this function:

◆ queryCol()

ilDBPdo::queryCol ( string  $query,
int  $type = PDO::FETCH_ASSOC,
int  $colnum = 0 
)

Implements ilDBPdoInterface.

Definition at line 1240 of file ilDBPdo.php.

1240 : array
1241 {
1242 $type = match ($type) {
1243 ilDBConstants::FETCHMODE_ASSOC => PDO::FETCH_ASSOC,
1244 ilDBConstants::FETCHMODE_OBJECT => PDO::FETCH_OBJ,
1245 default => PDO::FETCH_ASSOC,
1246 };
1247
1248 return $this->pdo->query($query, PDO::FETCH_ASSOC)->fetchAll(PDO::FETCH_COLUMN, $colnum);
1249 }
const FETCHMODE_OBJECT
const FETCHMODE_ASSOC

References ilDBConstants\FETCHMODE_ASSOC, and ilDBConstants\FETCHMODE_OBJECT.

◆ queryF()

ilDBPdo::queryF ( string  $query,
array  $types,
array  $values 
)
Parameters
string[]$types
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 791 of file ilDBPdo.php.

792 {
793 if (count($types) !== count($values)) {
794 throw new ilDatabaseException("ilDB::queryF: Types and values must be arrays of same size. ($query)");
795 }
796 $quoted_values = [];
797 foreach ($types as $k => $t) {
798 $quoted_values[] = $this->quote($values[$k], $t);
799 }
800 $query = vsprintf($query, $quoted_values);
801
802 return $this->query($query);
803 }

◆ queryRow()

ilDBPdo::queryRow ( string  $query,
?array  $types = null,
int  $fetchmode = ilDBConstants::FETCHMODE_DEFAULT 
)

Implements ilDBPdoInterface.

Definition at line 1251 of file ilDBPdo.php.

1255 : array {
1256 $type = match ($fetchmode) {
1257 ilDBConstants::FETCHMODE_ASSOC => PDO::FETCH_ASSOC,
1258 ilDBConstants::FETCHMODE_OBJECT => PDO::FETCH_OBJ,
1259 default => PDO::FETCH_ASSOC,
1260 };
1261
1262 return $this->pdo->query($query, $type)->fetch();
1263 }

References ilDBConstants\FETCHMODE_ASSOC, and ilDBConstants\FETCHMODE_OBJECT.

◆ quote()

ilDBPdo::quote (   $value,
?string  $type = null 
)

Definition at line 609 of file ilDBPdo.php.

609 : string
610 {
611 if ($value === null) {
612 return 'NULL';
613 }
614
615 $pdo_type = PDO::PARAM_STR;
616 switch ($type) {
620 if ($value === '') {
621 return 'NULL';
622 }
623 if ($value === $this->now()) {
624 return $value;
625 }
626 $value = (string) $value;
627 break;
629 return (string) (int) $value;
631 $pdo_type = PDO::PARAM_INT;
632 $value = (string) $value;
633 break;
635 default:
636 $value = (string) $value;
637 $pdo_type = PDO::PARAM_STR;
638 break;
639 }
640
641 return $this->pdo->quote((string) $value, $pdo_type);
642 }

References ILIAS\Repository\int(), ilDBConstants\T_DATE, ilDBConstants\T_DATETIME, ilDBConstants\T_FLOAT, ilDBConstants\T_INTEGER, ilDBConstants\T_TEXT, and ilDBConstants\T_TIMESTAMP.

+ Here is the call graph for this function:

◆ quoteIdentifier()

ilDBPdo::quoteIdentifier ( string  $identifier,
bool  $check_option = false 
)

Implements ilDBInterface.

Definition at line 176 of file ilDBPdo.php.

176 : string
177 {
178 return '`' . preg_replace('/[^a-zA-Z0-9_$]/', '', $identifier) . '`';
179 }

Referenced by nextId().

+ Here is the caller graph for this function:

◆ renameTable()

ilDBPdo::renameTable ( string  $name,
string  $new_name 
)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 1150 of file ilDBPdo.php.

1150 : bool
1151 {
1152 // check table name
1153 try {
1154 $this->checkTableName($new_name);
1155 } catch (ilDatabaseException $e) {
1156 throw new ilDatabaseException("ilDB Error: renameTable(" . $name . "," . $new_name . ")<br />" . $e->getMessage(), $e->getCode());
1157 }
1158
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)],
1164 false
1165 );
1166 }
1167 // The abstraction_progress is no longer used in ILIAS, see http://www.ilias.de/mantis/view.php?id=19513
1168 // $query = "UPDATE abstraction_progress " . "SET table_name = " . $this->quote($a_new_name, 'text') . " " . "WHERE table_name = "
1169 // . $this->quote($a_name, 'text');
1170 // $this->pdo->query($query);
1171
1172 return true;
1173 }

References Vendor\Package\$e.

◆ renameTableColumn()

ilDBPdo::renameTableColumn ( string  $table_name,
string  $column_old_name,
string  $column_new_name 
)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 435 of file ilDBPdo.php.

435 : bool
436 {
437 // check table name
438 if (!$this->checkColumnName($column_new_name)) {
439 throw new ilDatabaseException("ilDB Error: renameTableColumn(" . $table_name . "," . $column_old_name . "," . $column_new_name . ")");
440 }
441
442 $def = $this->reverse->getTableFieldDefinition($table_name, $column_old_name);
443
444 $analyzer = new ilDBAnalyzer($this);
445 $best_alt = $analyzer->getBestDefinitionAlternative($def);
446 $def = $def[$best_alt];
447 unset($def["nativetype"]);
448 unset($def["mdb2type"]);
449
450 $f["definition"] = $def;
451 $f["name"] = $column_new_name;
452
453 $changes = [
454 "rename" => [
455 $column_old_name => $f,
456 ],
457 ];
458
459 return $this->manager->alterTable($table_name, $changes, false);
460 }

References Vendor\Package\$f.

◆ replace()

ilDBPdo::replace ( string  $table,
array  $primary_keys,
array  $other_columns 
)

Replace into method.

Parameters
stringtable name
arrayprimary key values: array("field1" => array("text", $name), "field2" => ...)
arrayother values: array("field1" => array("text", $name), "field2" => ...)
Returns
int The number of rows affected by the manipulation

Implements ilDBInterface.

Definition at line 853 of file ilDBPdo.php.

853 : int
854 {
855 $a_columns = array_merge($primary_keys, $other_columns);
856 $fields = [];
857 $placeholders = [];
858 $types = [];
859 $values = [];
860
861 foreach ($a_columns as $k => $col) {
862 $fields[] = $this->quoteIdentifier($k);
863 $placeholders[] = "%s";
864 $placeholders2[] = ":$k";
865 $types[] = $col[0];
866
867 // integer auto-typecast (this casts bool values to integer)
868 if ($col[0] === 'integer' && !is_null($col[1])) {
869 $col[1] = (int) $col[1];
870 }
871
872 $values[] = $col[1];
873 }
874
875 $q = "REPLACE INTO " . $table . " (" . implode(",", $fields) . ") VALUES (" . implode(",", $placeholders) . ")";
876
877 return $this->manipulateF($q, $types, $values);
878 }
manipulateF(string $query, array $types, array $values)
Definition: ilDBPdo.php:809

References $q, and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ rollback()

ilDBPdo::rollback ( )
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 1216 of file ilDBPdo.php.

1216 : bool
1217 {
1218 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1219 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1220 }
1221
1222 return $this->pdo->rollBack();
1223 }

◆ sanitizeMB4StringIfNotSupported()

ilDBPdo::sanitizeMB4StringIfNotSupported ( string  $query)
Parameters
$querystring to sanitize, all MB4-Characters like emojis will re replaced with ???
Returns
string sanitized query

Implements ilDBInterface.

Definition at line 1459 of file ilDBPdo.php.

1459 : string
1460 {
1461 if (!$this->doesCollationSupportMB4Strings()) {
1462 $query_replaced = preg_replace(
1463 '/[\x{10000}-\x{10FFFF}]/u',
1465 $query
1466 );
1467 if (!empty($query_replaced)) {
1468 return $query_replaced;
1469 }
1470 }
1471
1472 return $query;
1473 }
const MB4_REPLACEMENT
doesCollationSupportMB4Strings()
Definition: ilDBPdo.php:1476

References ilDBConstants\MB4_REPLACEMENT.

◆ sequenceExists()

ilDBPdo::sequenceExists ( string  $sequence)

Implements ilDBInterface.

Definition at line 1064 of file ilDBPdo.php.

1064 : bool
1065 {
1066 return in_array($sequence, $this->listSequences(), true);
1067 }
listSequences()
Definition: ilDBPdo.php:1069

◆ setCharset()

ilDBPdo::setCharset ( string  $charset)

Definition at line 917 of file ilDBPdo.php.

917 : void
918 {
919 $this->charset = $charset;
920 }

◆ setDBHost()

ilDBPdo::setDBHost ( string  $host)

Implements ilDBInterface.

Definition at line 967 of file ilDBPdo.php.

967 : void
968 {
969 $this->setHost($host);
970 }

◆ setDbname()

ilDBPdo::setDbname ( string  $dbname)

Definition at line 907 of file ilDBPdo.php.

907 : void
908 {
909 $this->dbname = $dbname;
910 }

Referenced by createDatabase(), and initFromIniFile().

+ Here is the caller graph for this function:

◆ setDBPassword()

ilDBPdo::setDBPassword ( string  $password)

Implements ilDBInterface.

Definition at line 962 of file ilDBPdo.php.

962 : void
963 {
964 $this->setPassword($password);
965 }

◆ setDBPort()

ilDBPdo::setDBPort ( int  $port)

Implements ilDBInterface.

Definition at line 957 of file ilDBPdo.php.

957 : void
958 {
959 $this->setPort($port);
960 }

◆ setDBType()

ilDBPdo::setDBType ( string  $type)

Definition at line 739 of file ilDBPdo.php.

739 : void
740 {
741 $this->db_type = $type;
742 }

Referenced by initFromIniFile().

+ Here is the caller graph for this function:

◆ setDBUser()

ilDBPdo::setDBUser ( string  $user)

Implements ilDBInterface.

Definition at line 952 of file ilDBPdo.php.

952 : void
953 {
954 $this->setUsername($user);
955 }

◆ setFieldDefinition()

ilDBPdo::setFieldDefinition ( FieldDefinition  $field_definition)

Definition at line 115 of file ilDBPdo.php.

115 : void
116 {
117 $this->field_definition = $field_definition;
118 }

References $field_definition.

◆ setHost()

ilDBPdo::setHost ( string  $host)

Definition at line 897 of file ilDBPdo.php.

897 : void
898 {
899 $this->host = $host;
900 }

Referenced by initFromIniFile().

+ Here is the caller graph for this function:

◆ setLimit()

ilDBPdo::setLimit ( int  $limit,
int  $offset = 0 
)

Set the Limit for the next Query.

Implements ilDBInterface.

Definition at line 831 of file ilDBPdo.php.

831 : void
832 {
833 $this->limit = $limit;
834 $this->offset = $offset;
835 }
int $offset
Definition: ilDBPdo.php:49

◆ setPassword()

ilDBPdo::setPassword ( string  $password)

Definition at line 937 of file ilDBPdo.php.

937 : void
938 {
939 $this->password = $password;
940 }

Referenced by initFromIniFile().

+ Here is the caller graph for this function:

◆ setPort()

ilDBPdo::setPort ( int  $port)

Definition at line 947 of file ilDBPdo.php.

947 : void
948 {
949 $this->port = $port;
950 }

Referenced by initFromIniFile().

+ Here is the caller graph for this function:

◆ setStorageEngine()

ilDBPdo::setStorageEngine ( string  $storage_engine)

Implements ilDBInterface.

Definition at line 1230 of file ilDBPdo.php.

1230 : void
1231 {
1232 $this->storage_engine = $storage_engine;
1233 }

◆ setUsername()

ilDBPdo::setUsername ( string  $username)

Definition at line 927 of file ilDBPdo.php.

927 : void
928 {
929 $this->username = $username;
930 }

Referenced by initFromIniFile().

+ Here is the caller graph for this function:

◆ substr()

ilDBPdo::substr ( string  $a_exp,
int  $a_pos = 1,
int  $a_len = -1 
)

Definition at line 982 of file ilDBPdo.php.

982 : string
983 {
984 $lenstr = "";
985 if ($a_len > -1) {
986 $lenstr = ", " . $a_len;
987 }
988 return " SUBSTR(" . $a_exp . ", " . $a_pos . $lenstr . ") ";
989 }

◆ supports()

ilDBPdo::supports ( string  $feature)

Implements ilDBInterface.

Definition at line 1029 of file ilDBPdo.php.

1029 : bool
1030 {
1031 return match ($feature) {
1032 self::FEATURE_TRANSACTIONS => $this->supportsTransactions(),
1033 self::FEATURE_FULLTEXT => $this->supportsFulltext(),
1034 self::FEATURE_SLAVE => $this->supportsSlave(),
1035 default => false,
1036 };
1037 }
supportsTransactions()
Definition: ilDBPdo.php:1024
supportsSlave()
Definition: ilDBPdo.php:1014

◆ supportsCollationMigration()

ilDBPdo::supportsCollationMigration ( )

Implements ilDBPdoInterface.

Definition at line 1320 of file ilDBPdo.php.

1320 : bool
1321 {
1322 return true;
1323 }

◆ supportsEngineMigration()

ilDBPdo::supportsEngineMigration ( )

Implements ilDBPdoInterface.

Definition at line 1325 of file ilDBPdo.php.

1325 : bool
1326 {
1327 return true;
1328 }

◆ supportsFulltext()

ilDBPdo::supportsFulltext ( )

Implements ilDBInterface.

Definition at line 1019 of file ilDBPdo.php.

1019 : bool
1020 {
1021 return false;
1022 }

◆ supportsSlave()

ilDBPdo::supportsSlave ( )

Implements ilDBInterface.

Definition at line 1014 of file ilDBPdo.php.

1014 : bool
1015 {
1016 return false;
1017 }

◆ supportsTransactions()

ilDBPdo::supportsTransactions ( )

Implements ilDBInterface.

Definition at line 1024 of file ilDBPdo.php.

1024 : bool
1025 {
1026 return $this->details->supportsTransactions();
1027 }

◆ tableColumnExists()

ilDBPdo::tableColumnExists ( string  $table_name,
string  $column_name 
)

Implements ilDBInterface.

Definition at line 319 of file ilDBPdo.php.

319 : bool
320 {
321 return in_array($column_name, $this->manager->listTableFields($table_name), true);
322 }

◆ tableExists()

ilDBPdo::tableExists ( string  $table_name)

Implements ilDBInterface.

Definition at line 309 of file ilDBPdo.php.

309 : bool
310 {
311 $result = $this->pdo->prepare("SHOW TABLES LIKE :table_name");
312 $result->execute(['table_name' => $table_name]);
313 $return = $result->rowCount();
314 $result->closeCursor();
315
316 return $return > 0;
317 }

◆ uniqueConstraintExists()

ilDBPdo::uniqueConstraintExists ( string  $table,
array  $fields 
)

Implements ilDBPdoInterface.

Definition at line 1402 of file ilDBPdo.php.

1402 : bool
1403 {
1404 $analyzer = new ilDBAnalyzer();
1405 $cons = $analyzer->getConstraintsInformation($table);
1406 foreach ($cons as $c) {
1407 if ($c["type"] === "unique" && count($fields) === count($c["fields"])) {
1408 $all_in = true;
1409 foreach ($fields as $f) {
1410 if (!isset($c["fields"][$f])) {
1411 $all_in = false;
1412 }
1413 }
1414 if ($all_in) {
1415 return true;
1416 }
1417 }
1418 }
1419
1420 return false;
1421 }

References $c, and Vendor\Package\$f.

◆ unixTimestamp()

ilDBPdo::unixTimestamp ( )

Implements ilDBPdoInterface.

Definition at line 1441 of file ilDBPdo.php.

1441 : string
1442 {
1443 return "UNIX_TIMESTAMP()";
1444 }

◆ unlockTables()

ilDBPdo::unlockTables ( )
Exceptions

ilDatabaseException

Deprecated:
Use ilAtomQuery instead

Implements ilDBInterface.

Definition at line 777 of file ilDBPdo.php.

777 : void
778 {
779 $this->pdo->exec($this->manager->getQueryUtils()->unlock());
780 }

◆ update()

ilDBPdo::update ( string  $table_name,
array  $values,
array  $where 
)

@description $where MUST contain existing columns only.

statements like [1 => ['integer', 1]] will not work, use a full query and

See also
manipulate() instead in that case.
Returns
int The number of rows affected by the manipulation

Implements ilDBInterface.

Definition at line 491 of file ilDBPdo.php.

491 : int
492 {
493 $fields = [];
494 $field_values = [];
495 $placeholders = [];
496 $placeholders_full = [];
497 $types = [];
498 $values = [];
499 $lobs = false;
500 $lob = [];
501 foreach ($columns as $k => $col) {
502 $field_value = $col[1];
503 $fields[] = $k;
504 $placeholders[] = "%s";
505 $placeholders_full[] = ":$k";
506 $types[] = $col[0];
507
508 if (($col[0] === "blob" || $col[0] === "clob" || $col[0] === 'text') && is_string($field_value)) {
509 $field_value = $this->sanitizeMB4StringIfNotSupported($field_value);
510 }
511
512 // integer auto-typecast (this casts bool values to integer)
513 if ($col[0] === 'integer' && !is_null($field_value)) {
514 $field_value = (int) $field_value;
515 }
516
517 $values[] = $field_value;
518 $field_values[$k] = $field_value;
519 if ($col[0] === "blob" || $col[0] === "clob") {
520 $lobs = true;
521 }
522 }
523
524 if ($lobs) {
525 $q = "UPDATE " . $this->quoteIdentifier($table_name) . " SET ";
526 $lim = "";
527 foreach ($fields as $k => $field) {
528 $q .= $lim . $this->quoteIdentifier($field) . " = " . $placeholders_full[$k];
529 $lim = ", ";
530 }
531 $q .= " WHERE ";
532 $lim = "";
533 foreach ($where as $k => $col) {
534 $q .= $lim . $this->quoteIdentifier($k) . " = " . $this->quote($col[1], $col[0]);
535 $lim = " AND ";
536 }
537
538 $r = $this->prepareManip($q, $types);
539 $this->execute($r, $field_values);
540
541 $num_affected_rows = $r->rowCount();
542
543 $this->free($r);
544 } else {
545 foreach ($where as $k => $col) {
546 $types[] = $col[0];
547 $values[] = $col[1];
548 $field_values[$k] = $col;
549 }
550 $q = "UPDATE " . $this->quoteIdentifier($table_name) . " SET ";
551 $lim = "";
552 foreach ($fields as $k => $field) {
553 $q .= $lim . $this->quoteIdentifier($field) . " = " . $placeholders[$k];
554 $lim = ", ";
555 }
556 $q .= " WHERE ";
557 $lim = "";
558 foreach (array_keys($where) as $k) {
559 $q .= $lim . $this->quoteIdentifier($k) . " = %s";
560 $lim = " AND ";
561 }
562
563 $num_affected_rows = $this->manipulateF($q, $types, $values);
564 }
565
566 return $num_affected_rows;
567 }
free(ilDBStatement $a_st)
Definition: ilDBPdo.php:1142
prepareManip(string $query, ?array $types=null)
Definition: ilDBPdo.php:991

References $q, and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ upper()

ilDBPdo::upper ( string  $expression)

Implements ilDBInterface.

Definition at line 972 of file ilDBPdo.php.

972 : string
973 {
974 return " UPPER(" . $expression . ") ";
975 }

◆ useSlave()

ilDBPdo::useSlave ( bool  $bool)
Deprecated:

Implements ilDBInterface.

Definition at line 823 of file ilDBPdo.php.

823 : bool
824 {
825 return false;
826 }

Field Documentation

◆ $charset

string ilDBPdo::$charset = 'utf8'
private

Definition at line 41 of file ilDBPdo.php.

Referenced by generateDSN().

◆ $db_type

string ilDBPdo::$db_type = ''
private

Definition at line 52 of file ilDBPdo.php.

◆ $dbname

string ilDBPdo::$dbname = ''
private

Definition at line 40 of file ilDBPdo.php.

Referenced by generateDSN().

◆ $dsn

string ilDBPdo::$dsn = ''
private

Definition at line 51 of file ilDBPdo.php.

◆ $error_code

int ilDBPdo::$error_code = 0
private

Definition at line 53 of file ilDBPdo.php.

Referenced by getLastErrorCode().

◆ $field_definition

FieldDefinition ilDBPdo::$field_definition = null
private

Definition at line 54 of file ilDBPdo.php.

Referenced by getFieldDefinition(), and setFieldDefinition().

◆ $host

string ilDBPdo::$host = ''
private

Definition at line 39 of file ilDBPdo.php.

Referenced by generateDSN().

◆ $limit

int ilDBPdo::$limit = null
private

Definition at line 48 of file ilDBPdo.php.

◆ $manager

ilDBManager ilDBPdo::$manager
private

Definition at line 46 of file ilDBPdo.php.

◆ $offset

int ilDBPdo::$offset = null
private

Definition at line 49 of file ilDBPdo.php.

◆ $options

array ilDBPdo::$options = []

Definition at line 33 of file ilDBPdo.php.

◆ $password

string ilDBPdo::$password = ''
private

Definition at line 43 of file ilDBPdo.php.

◆ $pdo

PDO ilDBPdo::$pdo = null
private

Definition at line 45 of file ilDBPdo.php.

◆ $port

int ilDBPdo::$port = 3306
private

Definition at line 44 of file ilDBPdo.php.

Referenced by generateDSN().

◆ $reverse

ilDBReverse ilDBPdo::$reverse
private

Definition at line 47 of file ilDBPdo.php.

◆ $storage_engine

string ilDBPdo::$storage_engine = 'InnoDB'
private

Definition at line 50 of file ilDBPdo.php.

◆ $username

string ilDBPdo::$username = ''
private

Definition at line 42 of file ilDBPdo.php.

◆ FEATURE_FULLTEXT

const ilDBPdo::FEATURE_FULLTEXT = 'fulltext'

Definition at line 36 of file ilDBPdo.php.

◆ FEATURE_SLAVE

const ilDBPdo::FEATURE_SLAVE = 'slave'

Definition at line 37 of file ilDBPdo.php.

◆ FEATURE_TRANSACTIONS

const ilDBPdo::FEATURE_TRANSACTIONS = 'transactions'

Definition at line 35 of file ilDBPdo.php.

◆ SESSION_MODES

const ilDBPdo::SESSION_MODES
private
Initial value:
= [
'STRICT_TRANS_TABLES',
'STRICT_ALL_TABLES',
'IGNORE_SPACE',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
]

Definition at line 56 of file ilDBPdo.php.


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