ILIAS  release_8 Revision v8.24
ilDBPdo Class Reference

Class pdoDB. More...

+ Inheritance diagram for ilDBPdo:
+ Collaboration diagram for ilDBPdo:

Public Member Functions

 connect (bool $return_false_for_error=false)
 
 initHelpers ()
 
 getFieldDefinition ()
 
 setFieldDefinition (\ilDBPdoFieldDefinition $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, array $fields, string $a_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)
 TODO. More...
 
 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)
 
 enableResultBuffering (bool $a_status)
 
 supportsSlave ()
 
 supportsFulltext ()
 
 supportsTransactions ()
 
 supports (string $feature)
 
 listTables ()
 
 loadModule (string $module)
 
 getAllowedAttributes ()
 
Returns
string[]
More...
 
 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)
 @inheritDoc More...
 
 supportsCollationMigration ()
 @inheritDoc More...
 
 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)
 
Parameters
$querystring to sanitize, all MB4-Characters like emojis will re replaced with ???
Returns
string sanitized query
More...
 
 doesCollationSupportMB4Strings ()
 @inheritDoc More...
 
 groupConcat (string $a_field_name, string $a_seperator=",", ?string $a_order=null)
 
 cast (string $a_field_name, string $a_dest_type)
 
 primaryExistsByFields (string $table_name, array $fields)
 
- 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)
 
 primaryExistsByFields (string $table_name, array $fields)
 
- Public Member Functions inherited from ilDBPdoInterface
 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

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

Protected Attributes

string $host = ''
 
string $dbname = ''
 
string $charset = 'utf8'
 
string $username = ''
 
string $password = ''
 
int $port = 3306
 
PDO $pdo = null
 
ilDBPdoManager $manager
 
ilDBPdoReverse $reverse
 
int $limit = null
 
int $offset = null
 
string $storage_engine = 'InnoDB'
 
string $dsn = ''
 
array $attributes
 
string $db_type = ''
 
int $error_code = 0
 
ilDBPdoFieldDefinition $field_definition = null
 

Detailed Description

Member Function Documentation

◆ addFulltextIndex()

ilDBPdo::addFulltextIndex ( string  $table,
array  $fields,
string  $a_name = "in" 
)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQLInnoDB.

Definition at line 659 of file class.ilDBPdo.php.

659 : bool
660 {
661 $i_name = $this->constraintName($table, $a_name) . "_idx";
662 $f_str = implode(",", $fields);
663 $q = "ALTER TABLE $table ADD FULLTEXT $i_name ($f_str)";
664 $this->query($q);
665 return true;
666 }
query(string $query)
constraintName(string $a_table, string $a_constraint)
Determine contraint name by table name and constraint name.

◆ addIndex()

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

Implements ilDBInterface.

Definition at line 633 of file class.ilDBPdo.php.

633 : bool
634 {
635 assert(is_array($fields));
636 $this->field_definition->checkIndexName($index_name);
637
638 $definition_fields = array();
639 foreach ($fields as $f) {
640 $definition_fields[$f] = array();
641 }
642 $definition = array(
643 'fields' => $definition_fields,
644 );
645
646 if (!$fulltext) {
647 $this->manager->createIndex($table_name, $this->constraintName($table_name, $index_name), $definition);
648 } elseif ($this->supportsFulltext()) {
649 $this->addFulltextIndex($table_name, $fields, $index_name);
650 // TODO
651 }
652
653 return true;
654 }
addFulltextIndex(string $table, array $fields, string $a_name="in")

References Vendor\Package\$f.

◆ addPrimaryKey()

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

ilDatabaseException

Implements ilDBInterface.

Definition at line 232 of file class.ilDBPdo.php.

232 : bool
233 {
234 assert(is_array($primary_keys));
235
236 $fields = array();
237 foreach ($primary_keys as $f) {
238 $fields[$f] = array();
239 }
240 $definition = array(
241 'primary' => true,
242 'fields' => $fields,
243 );
244 $this->manager->createConstraint(
245 $table_name,
246 $this->constraintName($table_name, $this->getPrimaryKeyIdentifier()),
247 $definition
248 );
249
250 return true;
251 }
getPrimaryKeyIdentifier()

References Vendor\Package\$f.

◆ addTableColumn()

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

ilDatabaseException

Implements ilDBInterface.

Definition at line 301 of file class.ilDBPdo.php.

301 : bool
302 {
303 if (!$this->checkColumnName($column_name)) {
304 throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
305 }
306 if (!$this->checkColumnDefinition($attributes)) {
307 throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
308 }
309
310 $changes = array(
311 "add" => array(
312 $column_name => $attributes,
313 ),
314 );
315
316 return $this->manager->alterTable($table_name, $changes, false);
317 }
checkColumnName(string $a_name)
array $attributes
checkColumnDefinition(array $a_def, bool $a_modify_mode=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $attributes.

◆ addUniqueConstraint()

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

ilDatabaseException

Implements ilDBPdoInterface.

Definition at line 1345 of file class.ilDBPdo.php.

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

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

+ Here is the call graph for this function:

◆ appendLimit()

ilDBPdo::appendLimit ( string  $query)
protected

Definition at line 1088 of file class.ilDBPdo.php.

1088 : string
1089 {
1090 if ($this->limit !== null && $this->offset !== null) {
1091 $query .= ' LIMIT ' . $this->offset . ', ' . $this->limit;
1092 $this->limit = null;
1093 $this->offset = null;
1094
1095 return $query;
1096 }
1097
1098 return $query;
1099 }
$query

References $query.

◆ beginTransaction()

ilDBPdo::beginTransaction ( )
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 1204 of file class.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->beginTransaction();
1211 }
supports(string $feature)

◆ buildAtomQuery()

ilDBPdo::buildAtomQuery ( )

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQLGalera.

Definition at line 1398 of file class.ilDBPdo.php.

1398 : ilAtomQuery
1399 {
1400 return new ilAtomQueryLock($this);
1401 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ cast()

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

Implements ilDBInterface.

Definition at line 1499 of file class.ilDBPdo.php.

1499 : string
1500 {
1501 return $this->manager->getQueryUtils()->cast($a_field_name, $a_dest_type);
1502 }

◆ checkColumn()

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

Definition at line 211 of file class.ilDBPdo.php.

211 : bool
212 {
213 if (!$this->checkColumnName($a_col)) {
214 return false;
215 }
216 return $this->checkColumnDefinition($a_def);
217 }

◆ checkColumnDefinition()

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

Definition at line 219 of file class.ilDBPdo.php.

219 : bool
220 {
221 return $this->field_definition->checkColumnDefinition($a_def);
222 }

◆ checkColumnName()

ilDBPdo::checkColumnName ( string  $a_name)

Definition at line 224 of file class.ilDBPdo.php.

224 : bool
225 {
226 return $this->field_definition->checkColumnName($a_name);
227 }

◆ checkIndexName()

ilDBPdo::checkIndexName ( string  $name)
Exceptions

ilDatabaseException

Implements ilDBPdoInterface.

Definition at line 1333 of file class.ilDBPdo.php.

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

References $name.

◆ checkTableColumns()

ilDBPdo::checkTableColumns ( array  $a_cols)
protected

Definition at line 200 of file class.ilDBPdo.php.

200 : bool
201 {
202 foreach ($a_cols as $col => $def) {
203 if (!$this->checkColumn($col, $def)) {
204 return false;
205 }
206 }
207
208 return true;
209 }
checkColumn(string $a_col, array $a_def)

◆ checkTableName()

ilDBPdo::checkTableName ( string  $a_name)
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 1190 of file class.ilDBPdo.php.

1190 : bool
1191 {
1192 return $this->field_definition->checkTableName($a_name);
1193 }

◆ commit()

ilDBPdo::commit ( )
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 1216 of file class.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->commit();
1223 }

◆ concat()

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

Implements ilDBInterface.

Definition at line 1083 of file class.ilDBPdo.php.

1083 : string
1084 {
1085 return $this->manager->getQueryUtils()->concat($values, $allow_null);
1086 }

◆ connect()

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

Exception

Implements ilDBInterface.

Definition at line 58 of file class.ilDBPdo.php.

58 : ?bool
59 {
60 $this->generateDSN();
61 try {
62 $options = $this->getAttributes();
63 $this->pdo = new PDO($this->getDSN(), $this->getUsername(), $this->getPassword(), $options);
64 $this->initHelpers();
65 $this->initSQLMode();
66 } catch (Exception $e) {
67 $this->error_code = $e->getCode();
68 if ($return_false_for_error) {
69 return false;
70 }
71 throw $e;
72 }
73
74 return ($this->pdo->errorCode() === PDO::ERR_NONE);
75 }
array $options
getDSN()
Get DSN.
initHelpers()

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

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 707 of file class.ilDBPdo.php.

707 : string
708 {
709 return $a_constraint;
710 }

◆ createDatabase()

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

Implements ilDBInterface.

Definition at line 108 of file class.ilDBPdo.php.

108 : bool
109 {
110 $this->setDbname('');
111 $this->generateDSN();
112 $this->connect(true);
113 try {
114 $this->query($this->manager->getQueryUtils()->createDatabase($a_name, $a_charset, $a_collation));
115 return true;
116 } catch (PDOException $e) {
117 return false;
118 }
119 }
connect(bool $return_false_for_error=false)
setDbname(string $dbname)

References Vendor\Package\$e, 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 275 of file class.ilDBPdo.php.

275 : bool
276 {
277 $this->manager->createSequence($table_name, $start);
278 return true;
279 }

◆ createTable()

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

ilDatabaseException

Implements ilDBInterface.

Definition at line 177 of file class.ilDBPdo.php.

182 : bool {
183 // check table name
184 if (!$ignore_erros && !$this->checkTableName($table_name)) {
185 throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
186 }
187
188 // check definition array
189 if (!$ignore_erros && !$this->checkTableColumns($fields)) {
190 throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
191 }
192
193 if ($drop_table) {
194 $this->dropTable($table_name, false);
195 }
196
197 return $this->manager->createTable($table_name, $fields, array());
198 }
dropTable(string $table_name, bool $error_if_not_existing=true)
checkTableName(string $a_name)
checkTableColumns(array $a_cols)

◆ doesCollationSupportMB4Strings()

ilDBPdo::doesCollationSupportMB4Strings ( )

@inheritDoc

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQL.

Definition at line 1483 of file class.ilDBPdo.php.

1483 : bool
1484 {
1485 return false;
1486 }

◆ dropFulltextIndex()

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

Drop fulltext index.

Implements ilDBInterface.

Definition at line 671 of file class.ilDBPdo.php.

671 : bool
672 {
673 $i_name = $this->constraintName($a_table, $a_name) . "_idx";
674 $this->query("ALTER TABLE $a_table DROP FULLTEXT $i_name");
675 return true;
676 }

◆ dropIndex()

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

Implements ilDBInterface.

Definition at line 1237 of file class.ilDBPdo.php.

1237 : bool
1238 {
1239 return $this->manager->dropIndex($a_table, $a_name);
1240 }

◆ dropIndexByFields()

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

ilDatabaseException

Implements ilDBInterface.

Definition at line 256 of file class.ilDBPdo.php.

256 : bool
257 {
258 foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
259 $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
260 $idx_fields = array_keys($def['fields']);
261
262 if ($idx_fields === $fields) {
263 return $this->dropIndex($table_name, $idx_name);
264 }
265 }
266
267 return false;
268 }
dropIndex(string $a_table, string $a_name="i1")

◆ dropPrimaryKey()

ilDBPdo::dropPrimaryKey ( string  $table_name)

Implements ilDBPdoInterface.

Definition at line 1424 of file class.ilDBPdo.php.

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

◆ dropSequence()

ilDBPdo::dropSequence ( string  $table_name)

Implements ilDBInterface.

Definition at line 387 of file class.ilDBPdo.php.

387 : bool
388 {
389 $this->manager->dropSequence($table_name);
390 return true;
391 }

◆ dropTable()

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

ilDatabaseException

Implements ilDBInterface.

Definition at line 322 of file class.ilDBPdo.php.

322 : bool
323 {
324 $ilDBPdoManager = $this->loadModule(ilDBConstants::MODULE_MANAGER);
325 $tables = $ilDBPdoManager->listTables();
326 $table_exists = in_array($table_name, $tables);
327 if (!$table_exists && $error_if_not_existing) {
328 throw new ilDatabaseException("Table $table_name does not exist");
329 }
330
331 // drop sequence
332 $sequences = $ilDBPdoManager->listSequences();
333 if (in_array($table_name, $sequences)) {
334 $ilDBPdoManager->dropSequence($table_name);
335 }
336
337 // drop table
338 if ($table_exists) {
339 $ilDBPdoManager->dropTable($table_name);
340 }
341
342 return true;
343 }
loadModule(string $module)

References ilDBConstants\MODULE_MANAGER.

◆ dropTableColumn()

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

ilDatabaseException

Implements ilDBInterface.

Definition at line 396 of file class.ilDBPdo.php.

396 : bool
397 {
398 $changes = array(
399 "remove" => array(
400 $column_name => array(),
401 ),
402 );
403
404 return $this->manager->alterTable($table_name, $changes, false);
405 }

◆ dropUniqueConstraint()

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

Implements ilDBPdoInterface.

Definition at line 1367 of file class.ilDBPdo.php.

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

References $name.

◆ dropUniqueConstraintByFields()

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

Implements ilDBPdoInterface.

Definition at line 1372 of file class.ilDBPdo.php.

1372 : bool
1373 {
1374 $analyzer = new ilDBAnalyzer();
1375 $cons = $analyzer->getConstraintsInformation($table);
1376 foreach ($cons as $c) {
1377 if ($c["type"] === "unique" && count($fields) === count($c["fields"])) {
1378 $all_in = true;
1379 foreach ($fields as $f) {
1380 if (!isset($c["fields"][$f])) {
1381 $all_in = false;
1382 }
1383 }
1384 if ($all_in) {
1385 return $this->dropUniqueConstraint($table, $c['name']);
1386 }
1387 }
1388 }
1389
1390 return false;
1391 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
dropUniqueConstraint(string $table, string $name="con")
$c
Definition: cli.php:38

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

◆ enableResultBuffering()

ilDBPdo::enableResultBuffering ( bool  $a_status)

Implements ilDBInterface.

Definition at line 994 of file class.ilDBPdo.php.

994 : void
995 {
996 $this->pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $a_status);
997 }

◆ equals()

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

Implements ilDBInterface.

Definition at line 870 of file class.ilDBPdo.php.

870 : string
871 {
872 if (!$emptyOrNull || $value != "") {
873 return $columns . " = " . $this->quote($value, $type);
874 }
875
876 return "(" . $columns . " = '' OR $columns IS NULL)";
877 }
quote($value, ?string $type=null)
$type

References $type.

◆ escape()

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

Implements ilDBPdoInterface.

Definition at line 1294 of file class.ilDBPdo.php.

1294 : string
1295 {
1296 return $value;
1297 }

◆ escapePattern()

ilDBPdo::escapePattern ( string  $text)

Implements ilDBPdoInterface.

Definition at line 1299 of file class.ilDBPdo.php.

1299 : string
1300 {
1301 return $text;
1302 }

◆ executeMultiple()

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

Implements ilDBPdoInterface.

Definition at line 1429 of file class.ilDBPdo.php.

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

References $data.

◆ fetchAll()

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

Implements ilDBInterface.

Definition at line 377 of file class.ilDBPdo.php.

377 : array
378 {
379 $return = [];
380 while ($data = $statement->fetch($fetch_mode)) {
381 $return[] = $data;
382 }
383
384 return $return;
385 }
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 567 of file class.ilDBPdo.php.

567 : ?array
568 {
569 $res = $statement->fetch(PDO::FETCH_ASSOC);
570 if ($res === null || $res === false) {
571 $statement->closeCursor();
572
573 return null;
574 }
575
576 return $res;
577 }
$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 454 of file class.ilDBPdo.php.

454 : ?stdClass
455 {
456 $res = $query_result->fetchObject();
457 if ($res === null) {
458 $query_result->closeCursor();
459
460 return null;
461 }
462
463 return $res;
464 }

References $res, and ilDBStatement\fetchObject().

+ Here is the call graph for this function:

◆ free()

ilDBPdo::free ( ilDBStatement  $a_st)

Implements ilDBInterface.

Definition at line 1151 of file class.ilDBPdo.php.

1151 : void
1152 {
1153 $a_st->closeCursor();
1154 }

◆ fromUnixtime()

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

Implements ilDBPdoInterface.

Definition at line 1437 of file class.ilDBPdo.php.

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

◆ generateDSN()

ilDBPdo::generateDSN ( )

Definition at line 155 of file class.ilDBPdo.php.

156 {
157 $port = $this->getPort() !== 0 ? ";port=" . $this->getPort() : "";
158 $dbname = $this->getDbname() !== '' ? ';dbname=' . $this->getDbname() : '';
159 $host = $this->getHost();
160 $charset = ';charset=' . $this->getCharset();
161 $this->dsn = 'mysql:host=' . $host . $port . $dbname . $charset;
162 }
string $dbname
string $host
string $charset

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:

◆ getAdditionalAttributes()

ilDBPdo::getAdditionalAttributes ( )
protected

Reimplemented in ilDBPdoMySQL.

Definition at line 93 of file class.ilDBPdo.php.

93 : array
94 {
95 return array();
96 }

Referenced by getAttributes().

+ Here is the caller graph for this function:

◆ getAllowedAttributes()

ilDBPdo::getAllowedAttributes ( )

Returns
string[]

Implements ilDBInterface.

Definition at line 1068 of file class.ilDBPdo.php.

1068 : array
1069 {
1070 return $this->field_definition->getAllowedAttributes();
1071 }

◆ getAttributes()

ilDBPdo::getAttributes ( )
protected

Definition at line 83 of file class.ilDBPdo.php.

83 : array
84 {
86 foreach ($this->getAdditionalAttributes() as $k => $v) {
87 $options[$k] = $v;
88 }
89
90 return $options;
91 }
getAdditionalAttributes()

References $attributes, $options, and getAdditionalAttributes().

Referenced by connect().

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

◆ getCharset()

ilDBPdo::getCharset ( )

Definition at line 899 of file class.ilDBPdo.php.

899 : string
900 {
901 return $this->charset;
902 }

Referenced by generateDSN().

+ Here is the caller graph for this function:

◆ getDbname()

ilDBPdo::getDbname ( )

Definition at line 889 of file class.ilDBPdo.php.

889 : string
890 {
891 return $this->dbname;
892 }

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 717 of file class.ilDBPdo.php.

717 : string
718 {
719 return $this->db_type;
720 }
string $db_type

◆ getDBVersion()

ilDBPdo::getDBVersion ( )
Exceptions
ilDatabaseException

Implements ilDBPdoInterface.

Definition at line 1451 of file class.ilDBPdo.php.

1451 : string
1452 {
1453 $d = $this->fetchObject($this->query("SELECT VERSION() AS version"));
1454
1455 if ($d !== null && $d->version) {
1456 return $d->version;
1457 }
1458 return 'Unknown';
1459 }
fetchObject(ilDBStatement $query_result)
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296

References $d.

◆ getDSN()

ilDBPdo::getDSN ( )

Get DSN.

This must be overwritten in DBMS specific class.

Implements ilDBInterface.

Definition at line 712 of file class.ilDBPdo.php.

712 : string
713 {
714 return $this->dsn;
715 }
string $dsn

Referenced by connect().

+ Here is the caller graph for this function:

◆ getFieldDefinition()

ilDBPdo::getFieldDefinition ( )

Definition at line 98 of file class.ilDBPdo.php.

99 {
101 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilDBPdoFieldDefinition $field_definition

References $field_definition.

◆ getHost()

ilDBPdo::getHost ( )

Definition at line 879 of file class.ilDBPdo.php.

879 : string
880 {
881 return $this->host;
882 }

Referenced by generateDSN().

+ Here is the caller graph for this function:

◆ getIndexName()

ilDBPdo::getIndexName ( string  $index_name_base)

Definition at line 693 of file class.ilDBPdo.php.

693 : string
694 {
695 return sprintf(ilDBPdoFieldDefinition::INDEX_FORMAT, preg_replace('/[^a-z0-9_\$]/i', '_', $index_name_base));
696 }

References ilDBPdoFieldDefinition\INDEX_FORMAT.

◆ getLastErrorCode()

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

Definition at line 124 of file class.ilDBPdo.php.

125 {
126 if ($this->pdo instanceof PDO) {
127 return $this->pdo->errorCode();
128 }
129
130 return $this->error_code;
131 }
int $error_code

References $error_code.

◆ getLastInsertId()

ilDBPdo::getLastInsertId ( )

Implements ilDBPdoInterface.

Definition at line 1393 of file class.ilDBPdo.php.

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

◆ getPassword()

ilDBPdo::getPassword ( )

Definition at line 919 of file class.ilDBPdo.php.

919 : string
920 {
921 return $this->password;
922 }
string $password

Referenced by connect().

+ Here is the caller graph for this function:

◆ getPort()

ilDBPdo::getPort ( )

Definition at line 929 of file class.ilDBPdo.php.

929 : int
930 {
931 return $this->port;
932 }

Referenced by generateDSN().

+ Here is the caller graph for this function:

◆ getPrimaryKeyIdentifier()

ilDBPdo::getPrimaryKeyIdentifier ( )

Implements ilDBInterface.

Definition at line 270 of file class.ilDBPdo.php.

270 : string
271 {
272 return "PRIMARY";
273 }

◆ getSequenceName()

ilDBPdo::getSequenceName ( string  $table_name)

Implements ilDBInterface.

Definition at line 698 of file class.ilDBPdo.php.

698 : string
699 {
700 return sprintf(ilDBPdoFieldDefinition::SEQUENCE_FORMAT, preg_replace('/[^a-z0-9_\$.]/i', '_', $table_name));
701 }

References ilDBPdoFieldDefinition\SEQUENCE_FORMAT.

◆ getServerVersion()

ilDBPdo::getServerVersion ( bool  $native = false)

Implements ilDBPdoInterface.

Definition at line 1289 of file class.ilDBPdo.php.

1289 : int
1290 {
1291 return $this->pdo->query('SELECT VERSION()')->fetchColumn();
1292 }

◆ getStorageEngine()

ilDBPdo::getStorageEngine ( )

Implements ilDBInterface.

Definition at line 1247 of file class.ilDBPdo.php.

1247 : string
1248 {
1249 return $this->storage_engine;
1250 }
string $storage_engine

◆ getUsername()

ilDBPdo::getUsername ( )

Definition at line 909 of file class.ilDBPdo.php.

909 : string
910 {
911 return $this->username;
912 }
string $username

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 1491 of file class.ilDBPdo.php.

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

◆ in()

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

Implements ilDBInterface.

Definition at line 766 of file class.ilDBPdo.php.

766 : string
767 {
768 return $this->manager->getQueryUtils()->in($field, $values, $negate, $type);
769 }

References $type.

◆ indexExistsByFields()

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

Implements ilDBInterface.

Definition at line 619 of file class.ilDBPdo.php.

619 : bool
620 {
621 foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
622 $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
623 $idx_fields = array_keys($def['fields']);
624
625 if ($idx_fields === $fields) {
626 return true;
627 }
628 }
629
630 return false;
631 }

◆ initFromIniFile()

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

Implements ilDBInterface.

Definition at line 133 of file class.ilDBPdo.php.

133 : void
134 {
135 global $DIC;
136
137 if ($ini instanceof ilIniFile) {
138 $clientIniFile = $ini;
139 } elseif ($DIC->offsetExists('ilClientIniFile')) {
140 $clientIniFile = $DIC['ilClientIniFile'];
141 } else {
142 throw new InvalidArgumentException('$tmpClientIniFile is not an instance of ilIniFile');
143 }
144
145 $this->setUsername($clientIniFile->readVariable("db", "user"));
146 $this->setHost($clientIniFile->readVariable("db", "host"));
147 $this->setPort((int) $clientIniFile->readVariable("db", "port"));
148 $this->setPassword((string) $clientIniFile->readVariable("db", "pass"));
149 $this->setDbname($clientIniFile->readVariable("db", "name"));
150 $this->setDBType($clientIniFile->readVariable("db", "type"));
151
152 $this->generateDSN();
153 }
setUsername(string $username)
setPort(int $port)
setHost(string $host)
setDBType(string $type)
setPassword(string $password)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$ini
Definition: raiseError.php:4

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

+ Here is the call graph for this function:

◆ initHelpers()

ilDBPdo::initHelpers ( )
abstract

Reimplemented in ilDBPdoMySQL.

Referenced by connect().

+ Here is the caller graph for this function:

◆ initSQLMode()

ilDBPdo::initSQLMode ( )
protected

Reimplemented in ilDBPdoMySQL.

Definition at line 79 of file class.ilDBPdo.php.

79 : void
80 {
81 }

Referenced by connect().

+ Here is the caller graph for this function:

◆ insert()

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

Implements ilDBInterface.

Definition at line 437 of file class.ilDBPdo.php.

437 : int
438 {
439 $real = array();
440 $fields = array();
441 foreach ($values as $key => $val) {
442 $real[] = $this->quote($val[1], $val[0]);
443 $fields[] = $this->quoteIdentifier($key);
444 }
445 $values_string = implode(",", $real);
446 $fields_string = implode(",", $fields);
447 $query = "INSERT INTO " . $this->quoteIdentifier($table_name) . " (" . $fields_string . ") VALUES (" . $values_string . ")";
448
450
451 return (int) $this->pdo->exec($query);
452 }
sanitizeMB4StringIfNotSupported(string $query)
string sanitized query
quoteIdentifier(string $identifier, bool $check_option=false)
string $key
Consumer key/client ID value.
Definition: System.php:193

References ILIAS\LTI\ToolProvider\$key, and $query.

◆ isFulltextIndex()

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

Is index a fulltext index?

Implements ilDBInterface.

Definition at line 681 of file class.ilDBPdo.php.

681 : bool
682 {
683 $set = $this->query("SHOW INDEX FROM " . $a_table);
684 while ($rec = $this->fetchAssoc($set)) {
685 if ($rec["Key_name"] === $a_name && $rec["Index_type"] === "FULLTEXT") {
686 return true;
687 }
688 }
689
690 return false;
691 }
fetchAssoc(ilDBStatement $statement)

◆ isReservedWord()

static ilDBPdo::isReservedWord ( string  $a_word)
static

Implements ilDBInterface.

Definition at line 1195 of file class.ilDBPdo.php.

1195 : bool
1196 {
1197 global $DIC;
1198 return (new ilDBPdoMySQLFieldDefinition($DIC->database()))->isReserved($a_word);
1199 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $DIC.

◆ like()

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

ilDatabaseException

Implements ilDBInterface.

Definition at line 827 of file class.ilDBPdo.php.

827 : string
828 {
829 return $this->manager->getQueryUtils()->like($column, $type, $value, $case_insensitive);
830 }

References $type.

◆ listSequences()

ilDBPdo::listSequences ( )
Returns
string[]

Implements ilDBInterface.

Definition at line 1078 of file class.ilDBPdo.php.

1078 : array
1079 {
1080 return $this->manager->listSequences();
1081 }

◆ listTables()

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

Implements ilDBInterface.

Definition at line 1046 of file class.ilDBPdo.php.

1046 : array
1047 {
1048 return $this->manager->listTables();
1049 }

Referenced by ilDBPdoMySQL\migrateAllTablesToEngine().

+ Here is the caller graph for this function:

◆ loadModule()

ilDBPdo::loadModule ( string  $module)
Returns
\ilDBPdoManager|\ilDBPdoReverse

Implements ilDBInterface.

Definition at line 1054 of file class.ilDBPdo.php.

1055 {
1056 switch ($module) {
1058 return $this->manager;
1060 return $this->reverse;
1061 }
1062 throw new LogicException('module "' . $module . '" not available');
1063 }
ilDBPdoReverse $reverse

References ilDBConstants\MODULE_MANAGER, and ilDBConstants\MODULE_REVERSE.

◆ locate()

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

Implements ilDBInterface.

Definition at line 1101 of file class.ilDBPdo.php.

1101 : string
1102 {
1103 return $this->manager->getQueryUtils()->locate($needle, $string, $start_pos);
1104 }

◆ lockTables()

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

Implements ilDBInterface.

Definition at line 750 of file class.ilDBPdo.php.

750 : void
751 {
752 assert(is_array($tables));
753 $lock = $this->manager->getQueryUtils()->lock($tables);
754 $this->pdo->exec($lock);
755 }

◆ lower()

ilDBPdo::lower ( string  $expression)
Parameters
string$a_exp

Implements ilDBInterface.

Definition at line 970 of file class.ilDBPdo.php.

970 : string
971 {
972 return " LOWER(" . $expression . ") ";
973 }

◆ manipulate()

ilDBPdo::manipulate ( string  $query)
Exceptions
ilDatabaseException

Implements ilDBInterface.

Definition at line 547 of file class.ilDBPdo.php.

547 : int
548 {
549 global $DIC;
550 $ilBench = $DIC['ilBench'] ?? null;
551 try {
553 if ($ilBench instanceof ilBenchmark) {
554 $ilBench->startDbBench($query);
555 }
556 $num_affected_rows = $this->pdo->exec($query);
557 if ($ilBench instanceof ilBenchmark) {
558 $ilBench->stopDbBench();
559 }
560 } catch (PDOException $e) {
561 throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query, (int) $e->getCode());
562 }
563
564 return (int) $num_affected_rows;
565 }
Class ilBenchmark.

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

◆ manipulateF()

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

Implements ilDBInterface.

Definition at line 793 of file class.ilDBPdo.php.

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

References $query.

◆ migrateAllTablesToCollation()

ilDBPdo::migrateAllTablesToCollation ( string  $collation = ilDBConstants::MYSQL_COLLATION_UTF8MB4)

@inheritDoc

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoMySQL.

Definition at line 1312 of file class.ilDBPdo.php.

1312 : array
1313 {
1314 return array();
1315 }

◆ migrateAllTablesToEngine()

ilDBPdo::migrateAllTablesToEngine ( string  $engine = ilDBConstants::MYSQL_ENGINE_INNODB)
Returns
array of failed tables

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoMySQL.

Definition at line 1304 of file class.ilDBPdo.php.

1304 : array
1305 {
1306 return array();
1307 }

◆ modifyTableColumn()

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

ilDatabaseException

Implements ilDBInterface.

Definition at line 1109 of file class.ilDBPdo.php.

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

References Vendor\Package\$a, $attributes, and $type.

◆ nextId()

ilDBPdo::nextId ( string  $table_name)
abstract
Parameters
$table_namestring

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQL.

◆ now()

ilDBPdo::now ( )
Returns
string the now statement

Implements ilDBInterface.

Definition at line 835 of file class.ilDBPdo.php.

835 : string
836 {
837 return $this->manager->getQueryUtils()->now();
838 }

◆ numRows()

ilDBPdo::numRows ( ilDBStatement  $statement)

Implements ilDBInterface.

Definition at line 579 of file class.ilDBPdo.php.

579 : int
580 {
581 return $statement->rowCount();
582 }

References ilDBStatement\rowCount().

+ Here is the call graph for this function:

◆ prepare()

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

Definition at line 989 of file class.ilDBPdo.php.

990 {
991 return new ilPDOStatement($this->pdo->prepare($query));
992 }
Class ilPDOStatement is a Wrapper Class for PDOStatement.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $query.

◆ prepareManip()

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

Implements ilDBInterface.

Definition at line 984 of file class.ilDBPdo.php.

985 {
986 return new ilPDOStatement($this->pdo->prepare($query));
987 }

References $query.

◆ primaryExistsByFields()

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

Implements ilDBInterface.

Definition at line 1504 of file class.ilDBPdo.php.

1504 : bool
1505 {
1506 $constraints = $this->manager->listTableConstraints($table_name);
1507
1508 if (in_array('primary', $constraints)) {
1509 $definitions = $this->reverse->getTableConstraintDefinition($table_name, 'primary');
1510 $primary_fields = array_keys($definitions['fields']);
1511 sort($primary_fields);
1512 sort($fields);
1513
1514 return $primary_fields === $fields;
1515 }
1516 return false;
1517 }

◆ query()

ilDBPdo::query ( string  $query)
Exceptions
ilDatabaseException

Implements ilDBInterface.

Definition at line 348 of file class.ilDBPdo.php.

349 {
350 global $DIC;
351 $ilBench = $DIC['ilBench'] ?? null;
352
353 $query = $this->appendLimit($query);
354
355 try {
356 if ($ilBench instanceof ilBenchmark) {
357 $ilBench->startDbBench($query);
358 }
359 $res = $this->pdo->query($query);
360 if ($ilBench instanceof ilBenchmark) {
361 $ilBench->stopDbBench();
362 }
363 } catch (PDOException $e) {
364 throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query, (int) $e->getCode());
365 }
366
367 $err = $this->pdo->errorCode();
368 if ($err !== PDO::ERR_NONE) {
369 $info = $this->pdo->errorInfo();
370 $info_message = $info[2];
371 throw new ilDatabaseException($info_message . ' QUERY: ' . $query);
372 }
373
374 return new ilPDOStatement($res);
375 }
appendLimit(string $query)

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

Referenced by createDatabase().

+ 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 1252 of file class.ilDBPdo.php.

1252 : array
1253 {
1254 switch ($type) {
1256 $type = PDO::FETCH_ASSOC;
1257 break;
1259 $type = PDO::FETCH_OBJ;
1260 break;
1261 default:
1262 $type = PDO::FETCH_ASSOC;
1263 break;
1264 }
1265
1266 return $this->pdo->query($query, PDO::FETCH_ASSOC)->fetchAll(PDO::FETCH_COLUMN, $colnum);
1267 }

References $query, $type, ilDBConstants\FETCHMODE_ASSOC, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilDBPdoMySQL\migrateAllTablesToEngine().

+ Here is the caller graph for this function:

◆ queryF()

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

ilDatabaseException

Implements ilDBInterface.

Definition at line 775 of file class.ilDBPdo.php.

776 {
777 if (!is_array($types) || !is_array($values) || count($types) !== count($values)) {
778 throw new ilDatabaseException("ilDB::queryF: Types and values must be arrays of same size. ($query)");
779 }
780 $quoted_values = array();
781 foreach ($types as $k => $t) {
782 $quoted_values[] = $this->quote($values[$k], $t);
783 }
784 $query = vsprintf($query, $quoted_values);
785
786 return $this->query($query);
787 }

References $query.

◆ queryRow()

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

Implements ilDBPdoInterface.

Definition at line 1269 of file class.ilDBPdo.php.

1273 : array {
1274 switch ($fetchmode) {
1276 $type = PDO::FETCH_ASSOC;
1277 break;
1279 $type = PDO::FETCH_OBJ;
1280 break;
1281 default:
1282 $type = PDO::FETCH_ASSOC;
1283 break;
1284 }
1285
1286 return $this->pdo->query($query, $type)->fetch();
1287 }

References $type, ilDBConstants\FETCHMODE_ASSOC, and ilDBConstants\FETCHMODE_OBJECT.

◆ quote()

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

Definition at line 584 of file class.ilDBPdo.php.

584 : string
585 {
586 if ($value === null) {
587 return 'NULL';
588 }
589
590 $pdo_type = PDO::PARAM_STR;
591 switch ($type) {
595 if ($value === '') {
596 return 'NULL';
597 }
598 if ($value === $this->now()) {
599 return $value;
600 }
601 $value = (string) $value;
602 break;
604 return (string) (int) $value;
606 $pdo_type = PDO::PARAM_INT;
607 $value = (string) $value;
608 break;
610 default:
611 $value = (string) $value;
612 $pdo_type = PDO::PARAM_STR;
613 break;
614 }
615
616 return $this->pdo->quote((string) $value, $pdo_type);
617 }

References $type, 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 164 of file class.ilDBPdo.php.

164 : string
165 {
166 return '`' . preg_replace('/[^a-zA-Z0-9_$]/', '', $identifier) . '`';
167 }

Referenced by ilDBPdoManager\createConstraint().

+ Here is the caller graph for this function:

◆ renameTable()

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

ilDatabaseException

Implements ilDBInterface.

Definition at line 1159 of file class.ilDBPdo.php.

1159 : bool
1160 {
1161 // check table name
1162 try {
1163 $this->checkTableName($new_name);
1164 } catch (ilDatabaseException $e) {
1165 throw new ilDatabaseException(
1166 "ilDB Error: renameTable(" . $name . "," . $new_name . ")<br />" . $e->getMessage(),
1167 $e->getCode()
1168 );
1169 }
1170
1171 $this->manager->alterTable($name, ["name" => $new_name], false);
1172 if ($this->sequenceExists($name)) {
1173 $this->manager->alterTable(
1174 $this->getSequenceName($name),
1175 ["name" => $this->getSequenceName($new_name)],
1176 false
1177 );
1178 }
1179 // The abstraction_progress is no longer used in ILIAS, see http://www.ilias.de/mantis/view.php?id=19513
1180 // $query = "UPDATE abstraction_progress " . "SET table_name = " . $this->quote($a_new_name, 'text') . " " . "WHERE table_name = "
1181 // . $this->quote($a_name, 'text');
1182 // $this->pdo->query($query);
1183
1184 return true;
1185 }
sequenceExists(string $sequence)
getSequenceName(string $table_name)

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

◆ renameTableColumn()

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

ilDatabaseException

Implements ilDBInterface.

Definition at line 410 of file class.ilDBPdo.php.

410 : bool
411 {
412 // check table name
413 if (!$this->checkColumnName($column_new_name)) {
414 throw new ilDatabaseException("ilDB Error: renameTableColumn(" . $table_name . "," . $column_old_name . "," . $column_new_name . ")");
415 }
416
417 $def = $this->reverse->getTableFieldDefinition($table_name, $column_old_name);
418
419 $analyzer = new ilDBAnalyzer($this);
420 $best_alt = $analyzer->getBestDefinitionAlternative($def);
421 $def = $def[$best_alt];
422 unset($def["nativetype"]);
423 unset($def["mdb2type"]);
424
425 $f["definition"] = $def;
426 $f["name"] = $column_new_name;
427
428 $changes = array(
429 "rename" => array(
430 $column_old_name => $f,
431 ),
432 );
433
434 return $this->manager->alterTable($table_name, $changes, false);
435 }

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 840 of file class.ilDBPdo.php.

840 : int
841 {
842 $a_columns = array_merge($primary_keys, $other_columns);
843 $fields = [];
844 $placeholders = [];
845 $types = [];
846 $values = [];
847
848 foreach ($a_columns as $k => $col) {
849 $fields[] = $this->quoteIdentifier($k);
850 $placeholders[] = "%s";
851 $placeholders2[] = ":$k";
852 $types[] = $col[0];
853
854 // integer auto-typecast (this casts bool values to integer)
855 if ($col[0] === 'integer' && !is_null($col[1])) {
856 $col[1] = (int) $col[1];
857 }
858
859 $values[] = $col[1];
860 }
861
862 $q = "REPLACE INTO " . $table . " (" . implode(",", $fields) . ") VALUES (" . implode(",", $placeholders) . ")";
863
864 return $this->manipulateF($q, $types, $values);
865 }
manipulateF(string $query, array $types, array $values)

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ rollback()

ilDBPdo::rollback ( )
Exceptions

ilDatabaseException

Implements ilDBInterface.

Definition at line 1228 of file class.ilDBPdo.php.

1228 : bool
1229 {
1230 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1231 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1232 }
1233
1234 return $this->pdo->rollBack();
1235 }

◆ 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 1464 of file class.ilDBPdo.php.

1464 : string
1465 {
1466 if (!$this->doesCollationSupportMB4Strings()) {
1467 $query_replaced = preg_replace(
1468 '/[\x{10000}-\x{10FFFF}]/u',
1470 $query
1471 );
1472 if (!empty($query_replaced)) {
1473 return $query_replaced;
1474 }
1475 }
1476
1477 return $query;
1478 }
doesCollationSupportMB4Strings()
@inheritDoc

References $query, and ilDBConstants\MB4_REPLACEMENT.

◆ sequenceExists()

ilDBPdo::sequenceExists ( string  $sequence)

Implements ilDBInterface.

Definition at line 1073 of file class.ilDBPdo.php.

1073 : bool
1074 {
1075 return in_array($sequence, $this->listSequences(), true);
1076 }

Referenced by ilDBPdoMySQL\migrateAllTablesToEngine(), and ilDBPdoMySQL\migrateTableToEngine().

+ Here is the caller graph for this function:

◆ setCharset()

ilDBPdo::setCharset ( string  $charset)

Definition at line 904 of file class.ilDBPdo.php.

904 : void
905 {
906 $this->charset = $charset;
907 }

◆ setDBHost()

ilDBPdo::setDBHost ( string  $host)

Implements ilDBInterface.

Definition at line 954 of file class.ilDBPdo.php.

954 : void
955 {
956 $this->setHost($host);
957 }

◆ setDbname()

ilDBPdo::setDbname ( string  $dbname)

Definition at line 894 of file class.ilDBPdo.php.

894 : void
895 {
896 $this->dbname = $dbname;
897 }

Referenced by createDatabase(), and initFromIniFile().

+ Here is the caller graph for this function:

◆ setDBPassword()

ilDBPdo::setDBPassword ( string  $password)

Implements ilDBInterface.

Definition at line 949 of file class.ilDBPdo.php.

949 : void
950 {
951 $this->setPassword($password);
952 }

◆ setDBPort()

ilDBPdo::setDBPort ( int  $port)

Implements ilDBInterface.

Definition at line 944 of file class.ilDBPdo.php.

944 : void
945 {
946 $this->setPort($port);
947 }

◆ setDBType()

ilDBPdo::setDBType ( string  $type)

Definition at line 722 of file class.ilDBPdo.php.

722 : void
723 {
724 $this->db_type = $type;
725 }

References $type.

Referenced by initFromIniFile().

+ Here is the caller graph for this function:

◆ setDBUser()

ilDBPdo::setDBUser ( string  $user)

Implements ilDBInterface.

Definition at line 939 of file class.ilDBPdo.php.

939 : void
940 {
941 $this->setUsername($user);
942 }

◆ setFieldDefinition()

ilDBPdo::setFieldDefinition ( \ilDBPdoFieldDefinition  $field_definition)

Definition at line 103 of file class.ilDBPdo.php.

103 : void
104 {
105 $this->field_definition = $field_definition;
106 }

References $field_definition.

◆ setHost()

ilDBPdo::setHost ( string  $host)

Definition at line 884 of file class.ilDBPdo.php.

884 : void
885 {
886 $this->host = $host;
887 }

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 818 of file class.ilDBPdo.php.

818 : void
819 {
820 $this->limit = $limit;
821 $this->offset = $offset;
822 }

◆ setPassword()

ilDBPdo::setPassword ( string  $password)

Definition at line 924 of file class.ilDBPdo.php.

924 : void
925 {
926 $this->password = $password;
927 }

Referenced by initFromIniFile().

+ Here is the caller graph for this function:

◆ setPort()

ilDBPdo::setPort ( int  $port)

Definition at line 934 of file class.ilDBPdo.php.

934 : void
935 {
936 $this->port = $port;
937 }

Referenced by initFromIniFile().

+ Here is the caller graph for this function:

◆ setStorageEngine()

ilDBPdo::setStorageEngine ( string  $storage_engine)

Implements ilDBInterface.

Definition at line 1242 of file class.ilDBPdo.php.

1242 : void
1243 {
1244 $this->storage_engine = $storage_engine;
1245 }

◆ setUsername()

ilDBPdo::setUsername ( string  $username)

Definition at line 914 of file class.ilDBPdo.php.

914 : void
915 {
916 $this->username = $username;
917 }

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 975 of file class.ilDBPdo.php.

975 : string
976 {
977 $lenstr = "";
978 if ($a_len > -1) {
979 $lenstr = ", " . $a_len;
980 }
981 return " SUBSTR(" . $a_exp . ", " . $a_pos . $lenstr . ") ";
982 }

◆ supports()

ilDBPdo::supports ( string  $feature)

Implements ilDBInterface.

Definition at line 1029 of file class.ilDBPdo.php.

1029 : bool
1030 {
1031 switch ($feature) {
1033 return $this->supportsTransactions();
1035 return $this->supportsFulltext();
1037 return $this->supportsSlave();
1038 default:
1039 return false;
1040 }
1041 }
supportsTransactions()
const FEATURE_SLAVE
const FEATURE_TRANSACTIONS
const FEATURE_FULLTEXT

◆ supportsCollationMigration()

ilDBPdo::supportsCollationMigration ( )

@inheritDoc

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoMySQL.

Definition at line 1320 of file class.ilDBPdo.php.

1320 : bool
1321 {
1322 return false;
1323 }

◆ supportsEngineMigration()

ilDBPdo::supportsEngineMigration ( )

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoMySQL.

Definition at line 1325 of file class.ilDBPdo.php.

1325 : bool
1326 {
1327 return false;
1328 }

◆ supportsFulltext()

ilDBPdo::supportsFulltext ( )

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQLInnoDB.

Definition at line 1019 of file class.ilDBPdo.php.

1019 : bool
1020 {
1021 return false;
1022 }

◆ supportsSlave()

ilDBPdo::supportsSlave ( )

Implements ilDBInterface.

Definition at line 1014 of file class.ilDBPdo.php.

1014 : bool
1015 {
1016 return false;
1017 }

◆ supportsTransactions()

ilDBPdo::supportsTransactions ( )

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQL, ilDBPdoMySQLGalera, and ilDBPdoMySQLInnoDB.

Definition at line 1024 of file class.ilDBPdo.php.

1024 : bool
1025 {
1026 return false;
1027 }

◆ tableColumnExists()

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

Implements ilDBInterface.

Definition at line 291 of file class.ilDBPdo.php.

291 : bool
292 {
293 $fields = $this->loadModule(ilDBConstants::MODULE_MANAGER)->listTableFields($table_name);
294
295 return in_array($column_name, $fields, true);
296 }

References ilDBConstants\MODULE_MANAGER.

◆ tableExists()

ilDBPdo::tableExists ( string  $table_name)

Implements ilDBInterface.

Definition at line 281 of file class.ilDBPdo.php.

281 : bool
282 {
283 $result = $this->pdo->prepare("SHOW TABLES LIKE :table_name");
284 $result->execute(array('table_name' => $table_name));
285 $return = $result->rowCount();
286 $result->closeCursor();
287
288 return $return > 0;
289 }

◆ uniqueConstraintExists()

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

Implements ilDBPdoInterface.

Definition at line 1403 of file class.ilDBPdo.php.

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

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

◆ unixTimestamp()

ilDBPdo::unixTimestamp ( )

Implements ilDBPdoInterface.

Definition at line 1442 of file class.ilDBPdo.php.

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

◆ unlockTables()

ilDBPdo::unlockTables ( )
Exceptions

ilDatabaseException

Deprecated:
Use ilAtomQuery instead

Implements ilDBInterface.

Definition at line 761 of file class.ilDBPdo.php.

761 : void
762 {
763 $this->pdo->exec($this->manager->getQueryUtils()->unlock());
764 }

◆ 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 466 of file class.ilDBPdo.php.

466 : int
467 {
468 $fields = array();
469 $field_values = array();
470 $placeholders = array();
471 $placeholders_full = array();
472 $types = array();
473 $values = array();
474 $lobs = false;
475 $lob = array();
476 foreach ($columns as $k => $col) {
477 $field_value = $col[1];
478 $fields[] = $k;
479 $placeholders[] = "%s";
480 $placeholders_full[] = ":$k";
481 $types[] = $col[0];
482
483 if (($col[0] === "blob" || $col[0] === "clob" || $col[0] === 'text') && is_string($field_value)) {
484 $field_value = $this->sanitizeMB4StringIfNotSupported($field_value);
485 }
486
487 // integer auto-typecast (this casts bool values to integer)
488 if ($col[0] === 'integer' && !is_null($field_value)) {
489 $field_value = (int) $field_value;
490 }
491
492 $values[] = $field_value;
493 $field_values[$k] = $field_value;
494 if ($col[0] === "blob" || $col[0] === "clob") {
495 $lobs = true;
496 }
497 }
498
499 if ($lobs) {
500 $q = "UPDATE " . $this->quoteIdentifier($table_name) . " SET ";
501 $lim = "";
502 foreach ($fields as $k => $field) {
503 $q .= $lim . $this->quoteIdentifier($field) . " = " . $placeholders_full[$k];
504 $lim = ", ";
505 }
506 $q .= " WHERE ";
507 $lim = "";
508 foreach ($where as $k => $col) {
509 $q .= $lim . $this->quoteIdentifier($k) . " = " . $this->quote($col[1], $col[0]);
510 $lim = " AND ";
511 }
512
513 $r = $this->prepareManip($q, $types);
514 $this->execute($r, $field_values);
515
516 $num_affected_rows = $r->rowCount();
517
518 $this->free($r);
519 } else {
520 foreach ($where as $k => $col) {
521 $types[] = $col[0];
522 $values[] = $col[1];
523 $field_values[$k] = $col;
524 }
525 $q = "UPDATE " . $this->quoteIdentifier($table_name) . " SET ";
526 $lim = "";
527 foreach ($fields as $k => $field) {
528 $q .= $lim . $this->quoteIdentifier($field) . " = " . $placeholders[$k];
529 $lim = ", ";
530 }
531 $q .= " WHERE ";
532 $lim = "";
533 foreach (array_keys($where) as $k) {
534 $q .= $lim . $this->quoteIdentifier($k) . " = %s";
535 $lim = " AND ";
536 }
537
538 $num_affected_rows = $this->manipulateF($q, $types, $values);
539 }
540
541 return $num_affected_rows;
542 }
free(ilDBStatement $a_st)
prepareManip(string $query, ?array $types=null)

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ upper()

ilDBPdo::upper ( string  $expression)
Parameters
string$a_exp

Implements ilDBInterface.

Definition at line 962 of file class.ilDBPdo.php.

962 : string
963 {
964 return " UPPER(" . $expression . ") ";
965 }

◆ useSlave()

ilDBPdo::useSlave ( bool  $bool)

TODO.

Implements ilDBInterface.

Definition at line 810 of file class.ilDBPdo.php.

810 : bool
811 {
812 return false;
813 }

Field Documentation

◆ $attributes

array ilDBPdo::$attributes
protected
Initial value:
= array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
)

Definition at line 47 of file class.ilDBPdo.php.

Referenced by getAttributes().

◆ $charset

string ilDBPdo::$charset = 'utf8'
protected

Definition at line 33 of file class.ilDBPdo.php.

Referenced by generateDSN().

◆ $db_type

string ilDBPdo::$db_type = ''
protected

Definition at line 51 of file class.ilDBPdo.php.

◆ $dbname

string ilDBPdo::$dbname = ''
protected

Definition at line 32 of file class.ilDBPdo.php.

Referenced by generateDSN().

◆ $dsn

string ilDBPdo::$dsn = ''
protected

Definition at line 43 of file class.ilDBPdo.php.

◆ $error_code

int ilDBPdo::$error_code = 0
protected

Definition at line 52 of file class.ilDBPdo.php.

Referenced by getLastErrorCode().

◆ $field_definition

ilDBPdoFieldDefinition ilDBPdo::$field_definition = null
protected

Definition at line 53 of file class.ilDBPdo.php.

Referenced by getFieldDefinition(), and setFieldDefinition().

◆ $host

string ilDBPdo::$host = ''
protected

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

Referenced by generateDSN().

◆ $limit

int ilDBPdo::$limit = null
protected

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

◆ $manager

ilDBPdoManager ilDBPdo::$manager
protected

Definition at line 38 of file class.ilDBPdo.php.

◆ $offset

int ilDBPdo::$offset = null
protected

Definition at line 41 of file class.ilDBPdo.php.

◆ $options

array ilDBPdo::$options = []

Definition at line 27 of file class.ilDBPdo.php.

Referenced by getAttributes().

◆ $password

string ilDBPdo::$password = ''
protected

Definition at line 35 of file class.ilDBPdo.php.

◆ $pdo

PDO ilDBPdo::$pdo = null
protected

Definition at line 37 of file class.ilDBPdo.php.

◆ $port

int ilDBPdo::$port = 3306
protected

Definition at line 36 of file class.ilDBPdo.php.

Referenced by generateDSN().

◆ $reverse

ilDBPdoReverse ilDBPdo::$reverse
protected

Definition at line 39 of file class.ilDBPdo.php.

◆ $storage_engine

string ilDBPdo::$storage_engine = 'InnoDB'
protected

Definition at line 42 of file class.ilDBPdo.php.

◆ $username

string ilDBPdo::$username = ''
protected

Definition at line 34 of file class.ilDBPdo.php.

◆ FEATURE_FULLTEXT

const ilDBPdo::FEATURE_FULLTEXT = 'fulltext'

Definition at line 29 of file class.ilDBPdo.php.

◆ FEATURE_SLAVE

const ilDBPdo::FEATURE_SLAVE = 'slave'

Definition at line 30 of file class.ilDBPdo.php.

◆ FEATURE_TRANSACTIONS

const ilDBPdo::FEATURE_TRANSACTIONS = 'transactions'

Definition at line 28 of file class.ilDBPdo.php.


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