ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilDBPdo Class Reference

Class pdoDB. More...

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

Public Member Functions

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

Static Public Member Functions

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

Data Fields

const FEATURE_TRANSACTIONS = 'transactions'
 
const FEATURE_FULLTEXT = 'fulltext'
 
const FEATURE_SLAVE = 'slave'
 

Protected Member Functions

 initSQLMode ()
 
 getAttributes ()
 
 getAdditionalAttributes ()
 
 checkTableColumns ($a_cols)
 
 checkColumn ($a_col, $a_def)
 
 checkColumnDefinition ($a_def, $a_modify_mode=false)
 
 appendLimit ($query)
 
 autoPrepare ($table, $table_fields, $mode=ilDBConstants::AUTOQUERY_INSERT, $where=false, $types=null, $result_types=ilDBConstants::PREPARE_MANIP)
 
 buildManipSQL ($table, $table_fields, $mode, $where=false)
 

Protected Attributes

 $host = ''
 
 $dbname = ''
 
 $charset = 'utf8'
 
 $username = ''
 
 $password = ''
 
 $port = 3306
 
 $pdo
 
 $manager
 
 $reverse
 
 $limit = null
 
 $offset = null
 
 $storage_engine = 'MyISAM'
 
 $dsn = ''
 
 $attributes
 
 $db_type = ''
 
 $error_code = 0
 
 $field_definition
 

Detailed Description

Member Function Documentation

◆ addFulltextIndex()

ilDBPdo::addFulltextIndex (   $a_table,
  $a_fields,
  $a_name = "in" 
)
Parameters
$a_table
$a_fields
string$a_name
Exceptions

ilDatabaseException

Returns
bool

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQLInnoDB.

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

884 {
885 $i_name = $this->constraintName($a_table, $a_name) . "_idx";
886 $f_str = implode(",", $a_fields);
887 $q = "ALTER TABLE $a_table ADD FULLTEXT $i_name ($f_str)";
888 $this->query($q);
889 }
query($query)
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.

References constraintName(), and query().

Referenced by addIndex().

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

◆ addIndex()

ilDBPdo::addIndex (   $table_name,
  $fields,
  $index_name = '',
  $fulltext = false 
)
Parameters
$table_name
array$fields
$index_name
Returns
null

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

852 {
853 assert(is_array($fields));
854 $this->field_definition->checkIndexName($index_name);
855
856 $definition_fields = array();
857 foreach ($fields as $f) {
858 $definition_fields[$f] = array();
859 }
860 $definition = array(
861 'fields' => $definition_fields,
862 );
863
864 if (!$fulltext) {
865 $this->manager->createIndex($table_name, $this->constraintName($table_name, $index_name), $definition);
866 } else {
867 if ($this->supportsFulltext()) {
868 $this->addFulltextIndex($table_name, $fields, $index_name); // TODO
869 }
870 }
871
872 return true;
873 }
addFulltextIndex($a_table, $a_fields, $a_name="in")

References Vendor\Package\$f, addFulltextIndex(), constraintName(), and supportsFulltext().

+ Here is the call graph for this function:

◆ addPrimaryKey()

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

ilDatabaseException

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

343 {
344 assert(is_array($primary_keys));
345
346 $fields = array();
347 foreach ($primary_keys as $f) {
348 $fields[$f] = array();
349 }
350 $definition = array(
351 'primary' => true,
352 'fields' => $fields,
353 );
354 $this->manager->createConstraint($table_name, $this->constraintName($table_name, $this->getPrimaryKeyIdentifier()), $definition);
355
356 return true;
357 }
getPrimaryKeyIdentifier()

References Vendor\Package\$f, constraintName(), and getPrimaryKeyIdentifier().

+ Here is the call graph for this function:

◆ addTableColumn()

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

ilDatabaseException

Implements ilDBInterface.

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

440 {
441 if (!$this->checkColumnName($column_name)) {
442 throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
443 }
444 if (!$this->checkColumnDefinition($attributes)) {
445 throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
446 }
447
448 $changes = array(
449 "add" => array(
450 $column_name => $attributes,
451 ),
452 );
453
454 return $this->manager->alterTable($table_name, $changes, false);
455 }
checkColumnName($a_name)
checkColumnDefinition($a_def, $a_modify_mode=false)
Class ilDatabaseException.

References $attributes, checkColumnDefinition(), and checkColumnName().

+ Here is the call graph for this function:

◆ addUniqueConstraint()

ilDBPdo::addUniqueConstraint (   $table,
  $fields,
  $name = "con" 
)
Parameters
$table
$fields
string$name
Returns
bool
Exceptions

ilDatabaseException

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

1875 {
1876 assert(is_array($fields));
1878
1879 // check index name
1880 if (!$this->checkIndexName($name)) {
1881 throw new ilDatabaseException("ilDB Error: addUniqueConstraint(" . $table . "," . $name . ")");
1882 }
1883
1884 $fields_corrected = array();
1885 foreach ($fields as $f) {
1886 $fields_corrected[$f] = array();
1887 }
1888 $definition = array(
1889 'unique' => true,
1890 'fields' => $fields_corrected,
1891 );
1892
1893 return $manager->createConstraint($table, $this->constraintName($table, $name), $definition);
1894 }
checkIndexName($name)
if($format !==null) $name
Definition: metadata.php:230

References Vendor\Package\$f, $manager, $name, checkIndexName(), and constraintName().

+ Here is the call graph for this function:

◆ appendLimit()

ilDBPdo::appendLimit (   $query)
protected
Parameters
$query
Returns
string

Reimplemented in ilDBPdoPostgreSQL.

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

1529 {
1530 if ($this->limit !== null && $this->offset !== null) {
1531 $query .= ' LIMIT ' . (int) $this->offset . ', ' . (int) $this->limit;
1532 $this->limit = null;
1533 $this->offset = null;
1534
1535 return $query;
1536 }
1537
1538 return $query;
1539 }
$query

References $limit, and $query.

Referenced by query().

+ Here is the caller graph for this function:

◆ autoExecute()

ilDBPdo::autoExecute (   $tablename,
  $fields,
  $mode = ilDBConstants::AUTOQUERY_INSERT,
  $where = false 
)

Generate an insert, update or delete query and call prepare() and execute() on it.

Parameters
string$tablenameof the table
array$fields($key=>$value) where $key is a field name and $value its value
int$modeof query to build ilDBConstants::AUTOQUERY_INSERT ilDBConstants::AUTOQUERY_UPDATE ilDBConstants::AUTOQUERY_DELETE ilDBConstants::AUTOQUERY_SELECT
bool$where(in case of update and delete queries, this string will be put after the sql WHERE statement)
Deprecated:
Will be removed in ILIAS 5.3
Returns
bool

Implements ilDBPdoInterface.

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

2038 {
2039 $fields_values = (array) $fields;
2040 if ($mode == ilDBConstants::AUTOQUERY_INSERT) {
2041 if (!empty($fields_values)) {
2042 $keys = $fields_values;
2043 } else {
2044 $keys = array();
2045 }
2046 } else {
2047 $keys = array_keys($fields_values);
2048 }
2049 $params = array_values($fields_values);
2050 if (empty($params)) {
2051 $query = $this->buildManipSQL($tablename, $keys, $mode, $where);
2052 $result = $this->pdo->query($query);
2053 } else {
2054 $stmt = $this->autoPrepare($tablename, $keys, $mode, $where, $types, $result_types);
2055 $this->execute($stmt);
2056 $this->free($stmt);
2057 $result = $stmt;
2058 }
2059
2060 return $result;
2061 }
$result
buildManipSQL($table, $table_fields, $mode, $where=false)
autoPrepare($table, $table_fields, $mode=ilDBConstants::AUTOQUERY_INSERT, $where=false, $types=null, $result_types=ilDBConstants::PREPARE_MANIP)
execute($stmt, $data=array())
$keys
Definition: metadata.php:187

References $keys, $query, $result, autoPrepare(), ilDBConstants\AUTOQUERY_INSERT, buildManipSQL(), ilDBInterface\execute(), and ilDBInterface\free().

+ Here is the call graph for this function:

◆ autoPrepare()

ilDBPdo::autoPrepare (   $table,
  $table_fields,
  $mode = ilDBConstants::AUTOQUERY_INSERT,
  $where = false,
  $types = null,
  $result_types = ilDBConstants::PREPARE_MANIP 
)
protected
Parameters
$table
$table_fields
int$mode
bool$where
null$types
bool$result_types
Returns
string

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

2074 {
2075 $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
2076
2077 return $this->prepare($query, $types, $result_types);
2078 }
prepare($query, $types=null, $result_types=null)

References $query, buildManipSQL(), and prepare().

Referenced by autoExecute().

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

◆ beginTransaction()

ilDBPdo::beginTransaction ( )
Returns
bool
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

1674 {
1675 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1676 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1677 }
1678
1679 return $this->pdo->beginTransaction();
1680 }
supports($feature)

References supports().

Referenced by ilDBPdoPostgreSQL\lockTables().

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

◆ buildAtomQuery()

ilDBPdo::buildAtomQuery ( )
Returns
\ilAtomQuery

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQLGalera.

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

1948 {
1949 return new ilAtomQueryLock($this);
1950 }
Class ilAtomQueryLock.

◆ buildManipSQL()

ilDBPdo::buildManipSQL (   $table,
  $table_fields,
  $mode,
  $where = false 
)
protected
Parameters
$table
$table_fields
$mode
bool$where
Returns
string
Exceptions

ilDatabaseException

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

2090 {
2091 if ($this->options['quote_identifier']) {
2092 $table = $this->quoteIdentifier($table);
2093 }
2094
2095 if (!empty($table_fields) && $this->options['quote_identifier']) {
2096 foreach ($table_fields as $key => $field) {
2097 $table_fields[$key] = $this->quoteIdentifier($field);
2098 }
2099 }
2100
2101 if ($where !== false && !is_null($where)) {
2102 if (is_array($where)) {
2103 $where = implode(' AND ', $where);
2104 }
2105 $where = ' WHERE ' . $where;
2106 }
2107
2108 switch ($mode) {
2110 if (empty($table_fields)) {
2111 throw new ilDatabaseException('Insert requires table fields');
2112 }
2113 $cols = implode(', ', $table_fields);
2114 $values = '?' . str_repeat(', ?', (count($table_fields) - 1));
2115
2116 return 'INSERT INTO ' . $table . ' (' . $cols . ') VALUES (' . $values . ')';
2117 break;
2119 if (empty($table_fields)) {
2120 throw new ilDatabaseException('Update requires table fields');
2121 }
2122 $set = implode(' = ?, ', $table_fields) . ' = ?';
2123 $sql = 'UPDATE ' . $table . ' SET ' . $set . $where;
2124
2125 return $sql;
2126 break;
2128 $sql = 'DELETE FROM ' . $table . $where;
2129
2130 return $sql;
2131 break;
2133 $cols = !empty($table_fields) ? implode(', ', $table_fields) : '*';
2134 $sql = 'SELECT ' . $cols . ' FROM ' . $table . $where;
2135
2136 return $sql;
2137 break;
2138 }
2139
2140 throw new ilDatabaseException('Syntax error');
2141 }
quoteIdentifier($identifier, $check_option=false)
$cols
Definition: xhr_table.php:11

References $cols, ilDBConstants\AUTOQUERY_DELETE, ilDBConstants\AUTOQUERY_INSERT, ilDBConstants\AUTOQUERY_SELECT, ilDBConstants\AUTOQUERY_UPDATE, and quoteIdentifier().

Referenced by autoExecute(), and autoPrepare().

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

◆ cast()

ilDBPdo::cast (   $a_field_name,
  $a_dest_type 
)

Parameters
string$a_field_name
string$a_dest_type
Returns
string;

Implements ilDBInterface.

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

2196 {
2197 return $this->manager->getQueryUtils()->cast($a_field_name, $a_dest_type);
2198 }

◆ checkColumn()

ilDBPdo::checkColumn (   $a_col,
  $a_def 
)
protected
Parameters
$a_col
$a_def
Returns
bool

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

302 {
303 if (!$this->checkColumnName($a_col)) {
304 return false;
305 }
306
307 if (!$this->checkColumnDefinition($a_def)) {
308 return false;
309 }
310
311 return true;
312 }

References checkColumnDefinition(), and checkColumnName().

Referenced by checkTableColumns().

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

◆ checkColumnDefinition()

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

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

321 {
322 return $this->field_definition->checkColumnDefinition($a_def);
323 }

Referenced by addTableColumn(), checkColumn(), and modifyTableColumn().

+ Here is the caller graph for this function:

◆ checkColumnName()

ilDBPdo::checkColumnName (   $a_name)
Parameters
$a_name
Returns
bool

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

331 {
332 return $this->field_definition->checkColumnName($a_name);
333 }

Referenced by addTableColumn(), checkColumn(), and renameTableColumn().

+ Here is the caller graph for this function:

◆ checkIndexName()

ilDBPdo::checkIndexName (   $name)
Parameters
$name
Returns
bool
Exceptions

ilDatabaseException

Implements ilDBPdoInterface.

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

1862 {
1863 return $this->getFieldDefinition()->checkIndexName($name);
1864 }
getFieldDefinition()

References $name, and getFieldDefinition().

Referenced by addUniqueConstraint().

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

◆ checkTableColumns()

ilDBPdo::checkTableColumns (   $a_cols)
protected
Parameters
$a_cols
Returns
bool

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

285 {
286 foreach ($a_cols as $col => $def) {
287 if (!$this->checkColumn($col, $def)) {
288 return false;
289 }
290 }
291
292 return true;
293 }
checkColumn($a_col, $a_def)

References checkColumn().

Referenced by createTable().

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

◆ checkTableName()

ilDBPdo::checkTableName (   $a_name)
Parameters
$a_name
Returns
bool
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

1651 {
1652 return $this->field_definition->checkTableName($a_name);
1653 }

Referenced by createTable(), renameTable(), and ilDBPdoPostgreSQL\renameTable().

+ Here is the caller graph for this function:

◆ commit()

ilDBPdo::commit ( )
Returns
bool
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

1688 {
1689 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1690 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1691 }
1692
1693 return $this->pdo->commit();
1694 }

References supports().

Referenced by ilDBPdoPostgreSQL\unlockTables().

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

◆ concat()

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

Implements ilDBInterface.

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

1519 {
1520 return $this->manager->getQueryUtils()->concat($values, $allow_null);
1521 }

◆ connect()

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

Exception

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

94 {
95 $this->generateDSN();
96 try {
97 $options = $this->getAttributes();
98 $this->pdo = new PDO($this->getDSN(), $this->getUsername(), $this->getPassword(), $options);
99 $this->initHelpers();
100 $this->initSQLMode();
101 } catch (Exception $e) {
102 $this->error_code = $e->getCode();
103 if ($return_false_for_error) {
104 return false;
105 }
106 throw $e;
107 }
108
109 return ($this->pdo->errorCode() == PDO::ERR_NONE);
110 }
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 (   $a_table,
  $a_constraint 
)

Determine contraint name by table name and constraint name.

In MySQL these are "unique" per table

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

943 {
944 return $a_constraint;
945 }

Referenced by addFulltextIndex(), addIndex(), addPrimaryKey(), addUniqueConstraint(), dropFulltextIndex(), and dropUniqueConstraint().

+ Here is the caller graph for this function:

◆ createDatabase()

ilDBPdo::createDatabase (   $a_name,
  $a_charset = "utf8",
  $a_collation = "" 
)
Parameters
$a_name
string$a_charset
string$a_collation
Returns
ilPDOStatement|false
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

170 {
171 $this->setDbname(null);
172 $this->generateDSN();
173 $this->connect(true);
174 try {
175 return $this->query($this->manager->getQueryUtils()->createDatabase($a_name, $a_charset, $a_collation));
176 } catch (PDOException $e) {
177 return false;
178 }
179 }
connect($return_false_for_error=false)
setDbname($dbname)

References Vendor\Package\$e, connect(), generateDSN(), query(), and setDbname().

+ Here is the call graph for this function:

◆ createSequence()

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

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

395 {
396 $this->manager->createSequence($table_name, $start);
397 }

◆ createTable()

ilDBPdo::createTable (   $table_name,
  $fields,
  $drop_table = false,
  $ignore_erros = false 
)
Parameters
$table_name
$fields
bool$drop_table
bool$ignore_erros
Returns
mixed
Exceptions

ilDatabaseException

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

261 {
262 // check table name
263 if (!$this->checkTableName($table_name) && !$ignore_erros) {
264 throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
265 }
266
267 // check definition array
268 if (!$this->checkTableColumns($fields) && !$ignore_erros) {
269 throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
270 }
271
272 if ($drop_table) {
273 $this->dropTable($table_name, false);
274 }
275
276 return $this->manager->createTable($table_name, $fields, array());
277 }
checkTableName($a_name)
checkTableColumns($a_cols)
dropTable($table_name, $error_if_not_existing=true)

References checkTableColumns(), checkTableName(), and dropTable().

+ Here is the call graph for this function:

◆ doesCollationSupportMB4Strings()

ilDBPdo::doesCollationSupportMB4Strings ( )

@inheritDoc

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQL.

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

2179 {
2180 return false;
2181 }

Referenced by sanitizeMB4StringIfNotSupported().

+ Here is the caller graph for this function:

◆ dropFulltextIndex()

ilDBPdo::dropFulltextIndex (   $a_table,
  $a_name 
)

Drop fulltext index.

Implements ilDBInterface.

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

896 {
897 $i_name = $this->constraintName($a_table, $a_name) . "_idx";
898 $this->query("ALTER TABLE $a_table DROP FULLTEXT $i_name");
899 }

References constraintName(), and query().

+ Here is the call graph for this function:

◆ dropIndex()

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

Implements ilDBInterface.

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

1717 {
1718 return $this->manager->dropIndex($a_table, $a_name);
1719 }

Referenced by dropIndexByFields().

+ Here is the caller graph for this function:

◆ dropIndexByFields()

ilDBPdo::dropIndexByFields (   $table_name,
  $fields 
)
Parameters
$table_name
$fields
Returns
bool|mixed
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

367 {
368 foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
369 $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
370 $idx_fields = array_keys((array) $def['fields']);
371
372 if ($idx_fields === $fields) {
373 return $this->dropIndex($table_name, $idx_name);
374 }
375 }
376
377 return false;
378 }
dropIndex($a_table, $a_name="i1")

References dropIndex().

+ Here is the call graph for this function:

◆ dropPrimaryKey()

ilDBPdo::dropPrimaryKey (   $table_name)
Parameters
$table_name
Returns
bool

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

1985 {
1986 return $this->manager->dropConstraint($table_name, "PRIMARY", true);
1987 }

◆ dropSequence()

ilDBPdo::dropSequence (   $table_name)
Parameters
$table_namestring

Implements ilDBInterface.

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

547 {
548 $this->manager->dropSequence($table_name);
549 }

◆ dropTable()

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

ilDatabaseException

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

465 {
466 $ilDBPdoManager = $this->loadModule(ilDBConstants::MODULE_MANAGER);
467 $tables = $ilDBPdoManager->listTables();
468 $table_exists = in_array($table_name, $tables);
469 if (!$table_exists && $error_if_not_existing) {
470 throw new ilDatabaseException("Table {$table_name} does not exist");
471 }
472
473 // drop sequence
474 $sequences = $ilDBPdoManager->listSequences();
475 if (in_array($table_name, $sequences)) {
476 $ilDBPdoManager->dropSequence($table_name);
477 }
478
479 // drop table
480 if ($table_exists) {
481 $ilDBPdoManager->dropTable($table_name);
482 }
483
484 return true;
485 }
loadModule($module)

References loadModule(), and ilDBConstants\MODULE_MANAGER.

Referenced by createTable().

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

◆ dropTableColumn()

ilDBPdo::dropTableColumn (   $table_name,
  $column_name 
)
Parameters
string$table_name
string$column_name
Returns
bool
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

559 {
560 $changes = array(
561 "remove" => array(
562 $column_name => array(),
563 ),
564 );
565
566 return $this->manager->alterTable($table_name, $changes, false);
567 }

◆ dropUniqueConstraint()

ilDBPdo::dropUniqueConstraint (   $a_table,
  $a_name = "con" 
)
Parameters
$a_table
string$a_name
Returns
mixed

Implements ilDBPdoInterface.

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

1903 {
1904 return $this->manager->dropConstraint($a_table, $this->constraintName($a_table, $a_name), false);
1905 }

References constraintName().

Referenced by dropUniqueConstraintByFields().

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

◆ dropUniqueConstraintByFields()

ilDBPdo::dropUniqueConstraintByFields (   $a_table,
  $a_fields 
)
Parameters
$a_table
$a_fields
Returns
bool|mixed

Implements ilDBPdoInterface.

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

1914 {
1915 $analyzer = new ilDBAnalyzer();
1916 $cons = $analyzer->getConstraintsInformation($a_table);
1917 foreach ($cons as $c) {
1918 if ($c["type"] == "unique" && count($a_fields) == count($c["fields"])) {
1919 $all_in = true;
1920 foreach ($a_fields as $f) {
1921 if (!isset($c["fields"][$f])) {
1922 $all_in = false;
1923 }
1924 }
1925 if ($all_in) {
1926 return $this->dropUniqueConstraint($a_table, $c['name']);
1927 }
1928 }
1929 }
1930
1931 return false;
1932 }
This class gives all kind of DB information using the database manager and reverse module.
dropUniqueConstraint($a_table, $a_name="con")

References Vendor\Package\$c, Vendor\Package\$f, and dropUniqueConstraint().

+ Here is the call graph for this function:

◆ enableResultBuffering()

ilDBPdo::enableResultBuffering (   $a_status)
Parameters
$a_status

Implements ilDBInterface.

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

1391 {
1392 $this->pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $a_status);
1393 }

◆ equals()

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

Implements ilDBInterface.

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

1174 {
1175 if (!$emptyOrNull || $value != "") {
1176 return $columns . " = " . $this->quote($value, $type);
1177 } else {
1178 return "(" . $columns . " = '' OR $columns IS NULL)";
1179 }
1180 }
if(! $in) $columns
Definition: Utf8Test.php:45
quote($value, $type=null)
$type

References $columns, $type, and quote().

+ Here is the call graph for this function:

◆ escape()

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

Implements ilDBPdoInterface.

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

1804 {
1805 return $value;
1806 }

◆ escapePattern()

ilDBPdo::escapePattern (   $text)
Parameters
$text
Returns
string

Implements ilDBPdoInterface.

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

1814 {
1815 return $text;
1816 }

◆ executeMultiple()

ilDBPdo::executeMultiple (   $stmt,
  $a_data 
)
Parameters
$stmt
$a_data

Implements ilDBPdoInterface.

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

1995 {
1996 for ($i = 0, $j = count($a_data); $i < $j; $i++) {
1997 $stmt->execute($a_data[$i]);
1998 }
1999 }
$i
Definition: metadata.php:24

References $i.

◆ fetchAssoc()

ilDBPdo::fetchAssoc (   $query_result)
Parameters
$query_resultilPDOStatement
Returns
mixed

Implements ilDBInterface.

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

762 {
763 $res = $query_result->fetch(PDO::FETCH_ASSOC);
764 if ($res == null) {
765 $query_result->closeCursor();
766
767 return null;
768 }
769
770 return $res;
771 }
foreach($_POST as $key=> $value) $res

References $res.

Referenced by isFulltextIndex().

+ Here is the caller graph for this function:

◆ fetchObject()

ilDBPdo::fetchObject (   $query_result)
Parameters
$query_resultilPDOStatement
Returns
mixed|null

Implements ilDBInterface.

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

634 {
635 $res = $query_result->fetchObject();
636 if ($res == null) {
637 $query_result->closeCursor();
638
639 return null;
640 }
641
642 return $res;
643 }

References $res.

Referenced by getDBVersion().

+ Here is the caller graph for this function:

◆ fromUnixtime()

ilDBPdo::fromUnixtime (   $a_expr,
  $a_to_text = true 
)
Parameters
$a_expr
bool$a_to_text
Returns
string

Implements ilDBPdoInterface.

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

2008 {
2009 return "FROM_UNIXTIME(" . $a_expr . ")";
2010 }

◆ generateDSN()

ilDBPdo::generateDSN ( )

Reimplemented in ilDBPdoPostgreSQL.

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

225 {
226 $port = $this->getPort() ? ";port=" . $this->getPort() : "";
227 $dbname = $this->getDbname() ? ';dbname=' . $this->getDbname() : '';
228 $host = $this->getHost();
229 $charset = ';charset=' . $this->getCharset();
230 $this->dsn = 'mysql:host=' . $host . $port . $dbname . $charset;
231 }

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
Returns
array

Reimplemented in ilDBPdoMySQL, and ilDBPdoPostgreSQL.

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

139 {
140 return array();
141 }

Referenced by getAttributes().

+ Here is the caller graph for this function:

◆ getAllowedAttributes()

ilDBPdo::getAllowedAttributes ( )

Returns
array

Implements ilDBInterface.

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

1489 {
1490 return $this->field_definition->getAllowedAttributes();
1491 }

◆ getAttributes()

ilDBPdo::getAttributes ( )
protected
Returns
array

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

125 {
126 $options = $this->attributes;
127 foreach ($this->getAdditionalAttributes() as $k => $v) {
128 $options[$k] = $v;
129 }
130
131 return $options;
132 }
getAdditionalAttributes()

References $attributes, and getAdditionalAttributes().

Referenced by connect(), and ilDBPdoPostgreSQL\connect().

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

◆ getCharset()

ilDBPdo::getCharset ( )
Returns
string

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

1223 {
1224 return $this->charset;
1225 }

References $charset.

Referenced by generateDSN().

+ Here is the caller graph for this function:

◆ getDbname()

ilDBPdo::getDbname ( )
Returns
string

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

1205 {
1206 return $this->dbname;
1207 }

References $dbname.

Referenced by generateDSN(), and ilDBPdoPostgreSQL\generateDSN().

+ Here is the caller graph for this function:

◆ getDBType()

ilDBPdo::getDBType ( )
Returns
string

Implements ilDBInterface.

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

961 {
962 return $this->db_type;
963 }

References $db_type.

◆ getDBVersion()

ilDBPdo::getDBVersion ( )
Returns
string
Exceptions
ilDatabaseException

Implements ilDBPdoInterface.

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

2149 {
2150 $d = $this->fetchObject($this->query("SELECT VERSION() AS version"));
2151
2152 return ($d->version ? $d->version : 'Unknown');
2153 }
fetchObject($query_result)
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296

References $d, fetchObject(), and query().

+ Here is the call graph for this function:

◆ getDSN()

ilDBPdo::getDSN ( )
Returns
string

Implements ilDBInterface.

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

952 {
953 return $this->dsn;
954 }

References $dsn.

Referenced by connect(), and ilDBPdoPostgreSQL\connect().

+ Here is the caller graph for this function:

◆ getFieldDefinition()

ilDBPdo::getFieldDefinition ( )
Returns
ilDBPdoFieldDefinition

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

148 {
150 }

References $field_definition.

Referenced by checkIndexName().

+ Here is the caller graph for this function:

◆ getHost()

ilDBPdo::getHost ( )
Returns
string

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

1187 {
1188 return $this->host;
1189 }

References $host.

Referenced by generateDSN(), and ilDBPdoPostgreSQL\generateDSN().

+ Here is the caller graph for this function:

◆ getIndexName()

ilDBPdo::getIndexName (   $index_name_base)
Parameters
$index_name_base
Returns
string

Reimplemented in ilDBPdoPostgreSQL.

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

923 {
924 return sprintf(ilDBPdoFieldDefinition::INDEX_FORMAT, preg_replace('/[^a-z0-9_\$]/i', '_', $index_name_base));
925 }

References ilDBPdoFieldDefinition\INDEX_FORMAT.

◆ getLastErrorCode()

ilDBPdo::getLastErrorCode ( )
Returns
int

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

186 {
187 if ($this->pdo instanceof PDO) {
188 return $this->pdo->errorCode();
189 }
190
191 return $this->error_code;
192 }

References $error_code.

◆ getLastInsertId()

ilDBPdo::getLastInsertId ( )
Returns
string

Implements ilDBPdoInterface.

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

1939 {
1940 return $this->pdo->lastInsertId();
1941 }

◆ getPassword()

ilDBPdo::getPassword ( )
Returns
string

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

1259 {
1260 return $this->password;
1261 }

References $password.

Referenced by connect(), ilDBPdoPostgreSQL\connect(), and ilDBPdoPostgreSQL\generateDSN().

+ Here is the caller graph for this function:

◆ getPort()

ilDBPdo::getPort ( )
Returns
int

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

1277 {
1278 return $this->port;
1279 }

References $port.

Referenced by generateDSN(), and ilDBPdoPostgreSQL\generateDSN().

+ Here is the caller graph for this function:

◆ getPrimaryKeyIdentifier()

ilDBPdo::getPrimaryKeyIdentifier ( )
Returns
string

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

385 {
386 return "PRIMARY";
387 }

Referenced by addPrimaryKey().

+ Here is the caller graph for this function:

◆ getSequenceName()

ilDBPdo::getSequenceName (   $table_name)
Parameters
$table_name
Returns
string

Implements ilDBInterface.

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

933 {
934 return sprintf(ilDBPdoFieldDefinition::SEQUENCE_FORMAT, preg_replace('/[^a-z0-9_\$.]/i', '_', $table_name));
935 }

References ilDBPdoFieldDefinition\SEQUENCE_FORMAT.

Referenced by ilDBPdoMySQL\nextId(), renameTable(), and ilDBPdoPostgreSQL\renameTable().

+ Here is the caller graph for this function:

◆ getServerVersion()

ilDBPdo::getServerVersion (   $native = false)
Parameters
bool$native
Returns
string

Implements ilDBPdoInterface.

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

1793 {
1794 return $this->pdo->query('SELECT VERSION()')->fetchColumn();
1795 }

◆ getStorageEngine()

ilDBPdo::getStorageEngine ( )
Returns
string

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

1735 {
1736 return $this->storage_engine;
1737 }

References $storage_engine.

◆ getUsername()

ilDBPdo::getUsername ( )
Returns
string

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

1241 {
1242 return $this->username;
1243 }

References $username.

Referenced by connect(), ilDBPdoPostgreSQL\connect(), and ilDBPdoPostgreSQL\generateDSN().

+ Here is the caller graph for this function:

◆ groupConcat()

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

Parameters
string$a_field_name
string$a_seperator
string$a_order
Returns
string

Implements ilDBInterface.

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

2188 {
2189 return $this->manager->getQueryUtils()->groupConcat($a_field_name, $a_seperator, $a_order);
2190 }

◆ in()

ilDBPdo::in (   $field,
  $values,
  $negate = false,
  $type = "" 
)
Parameters
$fieldstring
$valuesarray
bool$negate
string$type
Returns
string

Implements ilDBInterface.

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

1029 {
1030 return $this->manager->getQueryUtils()->in($field, $values, $negate, $type);
1031 }

References $type.

◆ indexExistsByFields()

ilDBPdo::indexExistsByFields (   $table_name,
  $fields 
)
Parameters
string$table_name
array$fields
Returns
bool

Implements ilDBInterface.

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

831 {
832 foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
833 $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
834 $idx_fields = array_keys((array) $def['fields']);
835
836 if ($idx_fields === $fields) {
837 return true;
838 }
839 }
840
841 return false;
842 }

◆ initFromIniFile()

ilDBPdo::initFromIniFile (   $tmpClientIniFile = null)
Parameters
null$tmpClientIniFile

Implements ilDBInterface.

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

199 {
200 global $DIC;
201
202 if ($tmpClientIniFile instanceof ilIniFile) {
203 $clientIniFile = $tmpClientIniFile;
204 } else {
205 $ilClientIniFile = null;
206 if ($DIC->offsetExists('ilClientIniFile')) {
207 $clientIniFile = $DIC['ilClientIniFile'];
208 } else {
209 throw new InvalidArgumentException('$tmpClientIniFile is not an instance of ilIniFile');
210 }
211 }
212
213 $this->setUsername($clientIniFile->readVariable("db", "user"));
214 $this->setHost($clientIniFile->readVariable("db", "host"));
215 $this->setPort((int) $clientIniFile->readVariable("db", "port"));
216 $this->setPassword($clientIniFile->readVariable("db", "pass"));
217 $this->setDbname($clientIniFile->readVariable("db", "name"));
218 $this->setDBType($clientIniFile->readVariable("db", "type"));
219
220 $this->generateDSN();
221 }
setUsername($username)
setDBType($type)
setPort($port)
setPassword($password)
setHost($host)
INIFile Parser.
$DIC
Definition: xapitoken.php:46

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

+ Here is the call graph for this function:

◆ initHelpers()

ilDBPdo::initHelpers ( )
abstract

Reimplemented in ilDBPdoMySQL, and ilDBPdoPostgreSQL.

Referenced by connect().

+ Here is the caller graph for this function:

◆ initSQLMode()

ilDBPdo::initSQLMode ( )
protected

Reimplemented in ilDBPdoMySQL.

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

117 {
118 }

Referenced by connect().

+ Here is the caller graph for this function:

◆ insert()

ilDBPdo::insert (   $table_name,
  $values 
)
Parameters
$table_namestring
$values
Returns
int|void

Implements ilDBInterface.

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

611 {
612 $real = array();
613 $fields = array();
614 foreach ($values as $key => $val) {
615 $real[] = $this->quote($val[1], $val[0]);
616 $fields[] = $this->quoteIdentifier($key);
617 }
618 $values = implode(",", $real);
619 $fields = implode(",", $fields);
620 $query = "INSERT INTO " . $this->quoteIdentifier($table_name) . " (" . $fields . ") VALUES (" . $values . ")";
621
623
624 return $this->pdo->exec($query);
625 }
sanitizeMB4StringIfNotSupported($query)
string sanitized query

References $query, quote(), quoteIdentifier(), and sanitizeMB4StringIfNotSupported().

Referenced by ilDBPdoPostgreSQL\replace().

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

◆ isFulltextIndex()

ilDBPdo::isFulltextIndex (   $a_table,
  $a_name 
)

Is index a fulltext index?

Implements ilDBInterface.

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

906 {
907 $set = $this->query("SHOW INDEX FROM " . $a_table);
908 while ($rec = $this->fetchAssoc($set)) {
909 if ($rec["Key_name"] == $a_name && $rec["Index_type"] == "FULLTEXT") {
910 return true;
911 }
912 }
913
914 return false;
915 }
fetchAssoc($query_result)

References fetchAssoc(), and query().

+ Here is the call graph for this function:

◆ isReservedWord()

static ilDBPdo::isReservedWord (   $a_word)
static
Parameters
$a_word
Returns
bool

Implements ilDBInterface.

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

1661 {
1662 global $DIC;
1663 $ilDBPdoMySQLFieldDefinition = new ilDBPdoMySQLFieldDefinition($DIC->database());
1664
1665 return $ilDBPdoMySQLFieldDefinition->isReserved($a_word);
1666 }
Class ilDBPdoMySQLFieldDefinition.

References $DIC.

◆ like()

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

ilDatabaseException

Implements ilDBInterface.

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

1112 {
1113 return $this->manager->getQueryUtils()->like($column, $type, $value, $case_insensitive);
1114 }

References $type.

◆ listSequences()

ilDBPdo::listSequences ( )
Returns
array

Implements ilDBInterface.

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

1508 {
1509 return $this->manager->listSequences();
1510 }

Referenced by sequenceExists().

+ Here is the caller graph for this function:

◆ listTables()

ilDBPdo::listTables ( )
Returns
array

Implements ilDBInterface.

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

1465 {
1466 return $this->manager->listTables();
1467 }

Referenced by ilDBPdoMySQL\migrateAllTablesToEngine(), and ilDBPdoPostgreSQL\tableExists().

+ Here is the caller graph for this function:

◆ loadModule()

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

Implements ilDBInterface.

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

1475 {
1476 switch ($module) {
1478 return $this->manager;
1480 return $this->reverse;
1481 }
1482 }

References $manager, $reverse, ilDBConstants\MODULE_MANAGER, and ilDBConstants\MODULE_REVERSE.

Referenced by dropTable(), ilDBPdoMySQL\migrateAllTablesToCollation(), and tableColumnExists().

+ Here is the caller graph for this function:

◆ locate()

ilDBPdo::locate (   $a_needle,
  $a_string,
  $a_start_pos = 1 
)
Parameters
$a_needle
$a_string
int$a_start_pos
Returns
string

Implements ilDBInterface.

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

1549 {
1550 return $this->manager->getQueryUtils()->locate($a_needle, $a_string, $a_start_pos);
1551 }

◆ lockTables()

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

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

997 {
998 assert(is_array($tables));
999
1000 $lock = $this->manager->getQueryUtils()->lock($tables);
1001 global $DIC;
1002 $ilLogger = $DIC->logger()->root();
1003 if ($ilLogger instanceof ilLogger) {
1004 $ilLogger->log('ilDB::lockTables(): ' . $lock);
1005 }
1006
1007 $this->pdo->exec($lock);
1008 }
Component logger with individual log levels by component id.

References $DIC.

◆ lower()

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

Implements ilDBInterface.

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

1342 {
1343 return " LOWER(" . $a_exp . ") ";
1344 }

◆ manipulate()

ilDBPdo::manipulate (   $query)
Parameters
string$query
Returns
bool|int
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

736 {
737 global $DIC;
738 $ilBench = $DIC['ilBench'];
739 try {
741 if ($ilBench instanceof ilBenchmark) {
742 $ilBench->startDbBench($query);
743 }
744 $r = $this->pdo->exec($query);
745 if ($ilBench instanceof ilBenchmark) {
746 $ilBench->stopDbBench();
747 }
748 } catch (PDOException $e) {
749 throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query);
750 }
751
752 return $r;
753 }
performance measurement class
global $ilBench
Definition: ilias.php:18

References $DIC, Vendor\Package\$e, $ilBench, $query, and sanitizeMB4StringIfNotSupported().

Referenced by manipulateF(), and ilDBPdoPostgreSQL\replace().

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

◆ manipulateF()

ilDBPdo::manipulateF (   $query,
  $types,
  $values 
)
Parameters
$querystring
$typesstring[]
$valuesmixed[]
Returns
string
Exceptions
ilDatabaseException

Implements ilDBInterface.

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

1064 {
1065 if (!is_array($types) || !is_array($values) || count($types) != count($values)) {
1066 throw new ilDatabaseException("ilDB::manipulateF: types and values must be arrays of same size. ($query)");
1067 }
1068 $quoted_values = array();
1069 foreach ($types as $k => $t) {
1070 $quoted_values[] = $this->quote($values[$k], $t);
1071 }
1072 $query = vsprintf($query, $quoted_values);
1073
1074 return $this->manipulate($query);
1075 }
manipulate($query)

References $query, manipulate(), and quote().

Referenced by replace(), and update().

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

◆ migrateAllTablesToCollation()

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

@inheritDoc

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoMySQL.

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

1833 {
1834 return array();
1835 }

◆ migrateAllTablesToEngine()

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

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoMySQL.

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

1824 {
1825 return array();
1826 }

◆ modifyTableColumn()

ilDBPdo::modifyTableColumn (   $table,
  $a_column,
  $a_attributes 
)
Parameters
$table
$a_column
$a_attributes
Returns
bool
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

1562 {
1563 $def = $this->reverse->getTableFieldDefinition($table, $a_column);
1564
1565 $analyzer = new ilDBAnalyzer($this);
1566 $best_alt = $analyzer->getBestDefinitionAlternative($def);
1567 $def = $def[$best_alt];
1568 unset($def["nativetype"]);
1569 unset($def["mdb2type"]);
1570
1571 // check attributes
1572 $ilDBPdoFieldDefinition = $this->field_definition;
1573
1574 $type = ($a_attributes["type"] ?? "" != "") ? $a_attributes["type"] : $def["type"];
1575 foreach ($def as $k => $v) {
1576 if ($k != "type" && !$ilDBPdoFieldDefinition->isAllowedAttribute($k, $type)) {
1577 unset($def[$k]);
1578 }
1579 }
1580 $check_array = $def;
1581 foreach ($a_attributes as $k => $v) {
1582 $check_array[$k] = $v;
1583 }
1584 if (!$this->checkColumnDefinition($check_array, true)) {
1585 throw new ilDatabaseException("ilDB Error: modifyTableColumn(" . $table . ", " . $a_column . ")");
1586 }
1587
1588 foreach ($a_attributes as $a => $v) {
1589 $def[$a] = $v;
1590 }
1591
1592 $a_attributes["definition"] = $def;
1593
1594 $changes = array(
1595 "change" => array(
1596 $a_column => $a_attributes,
1597 ),
1598 );
1599
1600 return $this->manager->alterTable($table, $changes, false);
1601 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, $field_definition, $type, and checkColumnDefinition().

+ Here is the call graph for this function:

◆ nextId()

ilDBPdo::nextId (   $table_name)
abstract
Parameters
$table_namestring
Returns
int

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQL, and ilDBPdoPostgreSQL.

◆ now()

ilDBPdo::now ( )
Returns
string the now statement

Implements ilDBInterface.

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

1121 {
1122 return $this->manager->getQueryUtils()->now();
1123 }

◆ numRows()

ilDBPdo::numRows (   $query_result)
Parameters
$query_resultPDOStatement
Returns
int

Implements ilDBInterface.

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

780 {
781 return $query_result->rowCount();
782 }

◆ prepare()

ilDBPdo::prepare (   $query,
  $types = null,
  $result_types = null 
)
Parameters
$query
null$types
null$result_types
Returns
\ilPDOStatement

Implements ilDBInterface.

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

1382 {
1383 return new ilPDOStatement($this->pdo->prepare($query));
1384 }
Class ilPDOStatement is a Wrapper Class for PDOStatement.

References $query.

Referenced by autoPrepare().

+ Here is the caller graph for this function:

◆ prepareManip()

ilDBPdo::prepareManip (   $query,
  $types = null 
)
Parameters
$query
null$types
Returns
\ilPDOStatement

Implements ilDBInterface.

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

1370 {
1371 return new ilPDOStatement($this->pdo->prepare($query));
1372 }

References $query.

Referenced by update().

+ Here is the caller graph for this function:

◆ query()

ilDBPdo::query (   $query)
Parameters
$querystring
Returns
ilPDOStatement
Exceptions
ilDatabaseException

Implements ilDBInterface.

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

495 {
496 global $DIC;
497 $ilBench = $DIC['ilBench'];
498
499 $query = $this->appendLimit($query);
500
501 try {
502 if ($ilBench instanceof ilBenchmark) {
503 $ilBench->startDbBench($query);
504 }
505 $res = $this->pdo->query($query);
506 if ($ilBench instanceof ilBenchmark) {
507 $ilBench->stopDbBench();
508 }
509 } catch (PDOException $e) {
510 throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query);
511 }
512
513 $err = $this->pdo->errorCode();
514 if ($err != PDO::ERR_NONE) {
515 $info = $this->pdo->errorInfo();
516 $info_message = $info[2];
517 throw new ilDatabaseException($info_message . ' QUERY: ' . $query);
518 }
519
520 return new ilPDOStatement($res);
521 }
appendLimit($query)

References $DIC, Vendor\Package\$e, $ilBench, $query, $res, and appendLimit().

Referenced by addFulltextIndex(), createDatabase(), dropFulltextIndex(), getDBVersion(), isFulltextIndex(), ilDBPdoPostgreSQL\lockTables(), ilDBPdoMySQL\nextId(), ilDBPdoPostgreSQL\nextId(), and queryF().

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

◆ queryCol()

ilDBPdo::queryCol (   $query,
  $type = PDO::FETCH_ASSOC,
  $colnum = 0 
)
Parameters
$query
int$type
int$colnum
Returns
array

Implements ilDBPdoInterface.

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

1747 {
1748 switch ($type) {
1750 $type = PDO::FETCH_ASSOC;
1751 break;
1753 $type = PDO::FETCH_OBJ;
1754 break;
1755 default:
1756 $type = PDO::FETCH_ASSOC;
1757 break;
1758 }
1759
1760 return $this->pdo->query($query, PDO::FETCH_ASSOC)->fetchAll(PDO::FETCH_COLUMN, $colnum);
1761 }

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 (   $query,
  $types,
  $values 
)
Parameters
string$query
\string[]$types
\mixed[]$values
Returns
ilPDOStatement
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

1042 {
1043 if (!is_array($types) || !is_array($values) || count($types) != count($values)) {
1044 throw new ilDatabaseException("ilDB::queryF: Types and values must be arrays of same size. ($query)");
1045 }
1046 $quoted_values = array();
1047 foreach ($types as $k => $t) {
1048 $quoted_values[] = $this->quote($values[$k], $t);
1049 }
1050 $query = vsprintf($query, $quoted_values);
1051
1052 return $this->query($query);
1053 }

References $query, query(), and quote().

+ Here is the call graph for this function:

◆ queryRow()

ilDBPdo::queryRow (   $query,
  $types = null,
  $fetchmode = ilDBConstants::FETCHMODE_DEFAULT 
)
Parameters
$query
null$types
int$fetchmode
Returns
arary

Implements ilDBPdoInterface.

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

1771 {
1772 switch ($fetchmode) {
1774 $type = PDO::FETCH_ASSOC;
1775 break;
1777 $type = PDO::FETCH_OBJ;
1778 break;
1779 default:
1780 $type = PDO::FETCH_ASSOC;
1781 break;
1782 }
1783
1784 return $this->pdo->query($query, $type)->fetch();
1785 }

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

◆ quote()

ilDBPdo::quote (   $value,
  $type = null 
)
Parameters
$value
$type
Returns
mixed

Implements ilDBInterface.

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

792 {
793 if ($value === null) {
794 return 'NULL';
795 }
796
797 $pdo_type = PDO::PARAM_STR;
798 switch ($type) {
802 if ($value === '') {
803 return 'NULL';
804 }
805 break;
807 $value = (int) $value;
808
809 return $value;
810 break;
812 $pdo_type = PDO::PARAM_INT;
813 break;
815 default:
816 $pdo_type = PDO::PARAM_STR;
817 break;
818 }
819
820 return $this->pdo->quote($value, $pdo_type);
821 }

References $type, ilDBConstants\T_DATE, ilDBConstants\T_DATETIME, ilDBConstants\T_FLOAT, ilDBConstants\T_INTEGER, ilDBConstants\T_TEXT, and ilDBConstants\T_TIMESTAMP.

Referenced by equals(), insert(), manipulateF(), queryF(), ilDBPdoPostgreSQL\replace(), and update().

+ Here is the caller graph for this function:

◆ quoteIdentifier()

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

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

239 {
240 return '`' . $identifier . '`';
241 }

Referenced by buildManipSQL(), insert(), ilDBPdoMySQL\nextId(), and update().

+ Here is the caller graph for this function:

◆ renameTable()

ilDBPdo::renameTable (   $a_name,
  $a_new_name 
)
Parameters
$a_name
$a_new_name
Returns
bool
Exceptions

ilDatabaseException

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

1624 {
1625 // check table name
1626 try {
1627 $this->checkTableName($a_new_name);
1628 } catch (ilDatabaseException $e) {
1629 throw new ilDatabaseException("ilDB Error: renameTable(" . $a_name . "," . $a_new_name . ")<br />" . $e->getMessage());
1630 }
1631
1632 $this->manager->alterTable($a_name, ["name" => $a_new_name], false);
1633 if ($this->sequenceExists($a_name)) {
1634 $this->manager->alterTable($this->getSequenceName($a_name), ["name" => $this->getSequenceName($a_new_name)], false);
1635 }
1636 // The abstraction_progress is no longer used in ILIAS, see http://www.ilias.de/mantis/view.php?id=19513
1637 // $query = "UPDATE abstraction_progress " . "SET table_name = " . $this->quote($a_new_name, 'text') . " " . "WHERE table_name = "
1638 // . $this->quote($a_name, 'text');
1639 // $this->pdo->query($query);
1640
1641 return true;
1642 }
getSequenceName($table_name)
sequenceExists($sequence)

References Vendor\Package\$e, checkTableName(), getSequenceName(), and sequenceExists().

+ Here is the call graph for this function:

◆ renameTableColumn()

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

ilDatabaseException

Implements ilDBInterface.

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

578 {
579 // check table name
580 if (!$this->checkColumnName($column_new_name)) {
581 throw new ilDatabaseException("ilDB Error: renameTableColumn(" . $table_name . "," . $column_old_name . "," . $column_new_name . ")");
582 }
583
584 $def = $this->reverse->getTableFieldDefinition($table_name, $column_old_name);
585
586 $analyzer = new ilDBAnalyzer($this);
587 $best_alt = $analyzer->getBestDefinitionAlternative($def);
588 $def = $def[$best_alt];
589 unset($def["nativetype"]);
590 unset($def["mdb2type"]);
591
592 $f["definition"] = $def;
593 $f["name"] = $column_new_name;
594
595 $changes = array(
596 "rename" => array(
597 $column_old_name => $f,
598 ),
599 );
600
601 return $this->manager->alterTable($table_name, $changes, false);
602 }

References Vendor\Package\$f, and checkColumnName().

+ Here is the call graph for this function:

◆ replace()

ilDBPdo::replace (   $table,
  $primaryKeys,
  $otherColumns 
)

Replace into method.

Parameters
stringtable name
arrayprimary key values: array("field1" => array("text", $name), "field2" => ...)
arrayother values: array("field1" => array("text", $name), "field2" => ...)
Returns
string

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

1135 {
1136 $a_columns = array_merge($primaryKeys, $otherColumns);
1137 $fields = array();
1138 $field_values = array();
1139 $placeholders = array();
1140 $types = array();
1141 $values = array();
1142
1143 foreach ($a_columns as $k => $col) {
1144 $fields[] = $k;
1145 $placeholders[] = "%s";
1146 $placeholders2[] = ":$k";
1147 $types[] = $col[0];
1148
1149 // integer auto-typecast (this casts bool values to integer)
1150 if ($col[0] == 'integer' && !is_null($col[1])) {
1151 $col[1] = (int) $col[1];
1152 }
1153
1154 $values[] = $col[1];
1155 $field_values[$k] = $col[1];
1156 }
1157
1158 $q = "REPLACE INTO " . $table . " (" . implode(",", $fields) . ") VALUES (" . implode(",", $placeholders) . ")";
1159
1160 $r = $this->manipulateF($q, $types, $values);
1161
1162 return $r;
1163 }
manipulateF($query, $types, $values)

References manipulateF().

+ Here is the call graph for this function:

◆ rollback()

ilDBPdo::rollback ( )
Returns
bool
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

1702 {
1703 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1704 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1705 }
1706
1707 return $this->pdo->rollBack();
1708 }

References supports().

+ Here is the call graph for this function:

◆ sanitizeMB4StringIfNotSupported()

ilDBPdo::sanitizeMB4StringIfNotSupported (   $query)

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

Implements ilDBInterface.

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

2160 {
2161 if (!$this->doesCollationSupportMB4Strings()) {
2162 $query_replaced = preg_replace(
2163 '/[\x{10000}-\x{10FFFF}]/u',
2165 $query
2166 );
2167 if (!empty($query_replaced)) {
2168 return $query_replaced;
2169 }
2170 }
2171
2172 return $query;
2173 }
doesCollationSupportMB4Strings()
@inheritDoc

References $query, doesCollationSupportMB4Strings(), and ilDBConstants\MB4_REPLACEMENT.

Referenced by insert(), manipulate(), and update().

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

◆ sequenceExists()

ilDBPdo::sequenceExists (   $sequence)
Parameters
$sequence
Returns
bool

Implements ilDBInterface.

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

1499 {
1500 return in_array($sequence, $this->listSequences());
1501 }

References listSequences().

Referenced by renameTable(), and ilDBPdoPostgreSQL\renameTable().

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

◆ setCharset()

ilDBPdo::setCharset (   $charset)
Parameters
string$charset

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

1232 {
1233 $this->charset = $charset;
1234 }

References $charset.

◆ setDBHost()

ilDBPdo::setDBHost (   $host)
Parameters
$host

Implements ilDBInterface.

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

1322 {
1323 $this->setHost($host);
1324 }

References $host, and setHost().

+ Here is the call graph for this function:

◆ setDbname()

ilDBPdo::setDbname (   $dbname)
Parameters
string$dbname

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

1214 {
1215 $this->dbname = $dbname;
1216 }

References $dbname.

Referenced by createDatabase(), and initFromIniFile().

+ Here is the caller graph for this function:

◆ setDBPassword()

ilDBPdo::setDBPassword (   $password)
Parameters
$password

Implements ilDBInterface.

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

1313 {
1314 $this->setPassword($password);
1315 }

References $password, and setPassword().

+ Here is the call graph for this function:

◆ setDBPort()

ilDBPdo::setDBPort (   $port)
Parameters
$port

Implements ilDBInterface.

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

1304 {
1305 $this->setPort($port);
1306 }

References $port, and setPort().

+ Here is the call graph for this function:

◆ setDBType()

ilDBPdo::setDBType (   $type)
Parameters
string$type

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

971 {
972 $this->db_type = $type;
973 }

References $type.

Referenced by initFromIniFile().

+ Here is the caller graph for this function:

◆ setDBUser()

ilDBPdo::setDBUser (   $user)
Parameters
$user

Implements ilDBInterface.

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

1295 {
1296 $this->setUsername($user);
1297 }

References setUsername().

+ Here is the call graph for this function:

◆ setFieldDefinition()

ilDBPdo::setFieldDefinition (   $field_definition)
Parameters
ilDBPdoFieldDefinition$field_definition

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

157 {
158 $this->field_definition = $field_definition;
159 }

References $field_definition.

◆ setHost()

ilDBPdo::setHost (   $host)
Parameters
string$host

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

1196 {
1197 $this->host = $host;
1198 }

References $host.

Referenced by initFromIniFile(), and setDBHost().

+ Here is the caller graph for this function:

◆ setLimit()

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

Set the Limit for the next Query.

Parameters
$limit
$offset

Implements ilDBInterface.

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

1097 {
1098 $this->limit = $limit;
1099 $this->offset = $offset;
1100 }

References $limit, and $offset.

◆ setPassword()

ilDBPdo::setPassword (   $password)
Parameters
string$password

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

1268 {
1269 $this->password = $password;
1270 }

References $password.

Referenced by initFromIniFile(), and setDBPassword().

+ Here is the caller graph for this function:

◆ setPort()

ilDBPdo::setPort (   $port)
Parameters
int$port

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

1286 {
1287 $this->port = $port;
1288 }

References $port.

Referenced by ilDBPdoPostgreSQL\generateDSN(), initFromIniFile(), and setDBPort().

+ Here is the caller graph for this function:

◆ setStorageEngine()

ilDBPdo::setStorageEngine (   $storage_engine)
Parameters
$storage_engine

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

1726 {
1727 $this->storage_engine = $storage_engine;
1728 }

References $storage_engine.

◆ setUsername()

ilDBPdo::setUsername (   $username)
Parameters
string$username

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

1250 {
1251 $this->username = $username;
1252 }

References $username.

Referenced by initFromIniFile(), and setDBUser().

+ Here is the caller graph for this function:

◆ substr()

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

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

1354 {
1355 $lenstr = "";
1356 if ($a_len > -1) {
1357 $lenstr = ", " . $a_len;
1358 }
1359
1360 return " SUBSTR(" . $a_exp . ", " . $a_pos . $lenstr . ") ";
1361 }

◆ supports()

ilDBPdo::supports (   $feature)
Parameters
$feature
Returns
bool

Implements ilDBInterface.

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

1447 {
1448 switch ($feature) {
1450 return $this->supportsTransactions();
1452 return $this->supportsFulltext();
1454 return $this->supportsSlave();
1455 default:
1456 return false;
1457 }
1458 }
supportsTransactions()
const FEATURE_SLAVE
const FEATURE_TRANSACTIONS
const FEATURE_FULLTEXT

References FEATURE_FULLTEXT, FEATURE_SLAVE, FEATURE_TRANSACTIONS, supportsFulltext(), supportsSlave(), and supportsTransactions().

Referenced by beginTransaction(), commit(), and rollback().

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

◆ supportsCollationMigration()

ilDBPdo::supportsCollationMigration ( )

@inheritDoc

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoMySQL.

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

1842 {
1843 return false;
1844 }

◆ supportsEngineMigration()

ilDBPdo::supportsEngineMigration ( )
Returns
bool

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoMySQL.

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

1851 {
1852 return false;
1853 }

◆ supportsFulltext()

ilDBPdo::supportsFulltext ( )
Returns
bool

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQLInnoDB, ilDBPdoMySQLMyISAM, and ilDBPdoPostgreSQL.

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

1428 {
1429 return false;
1430 }

Referenced by addIndex(), and supports().

+ Here is the caller graph for this function:

◆ supportsSlave()

ilDBPdo::supportsSlave ( )
Returns
bool

Implements ilDBInterface.

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

1419 {
1420 return false;
1421 }

Referenced by supports().

+ Here is the caller graph for this function:

◆ supportsTransactions()

ilDBPdo::supportsTransactions ( )
Returns
bool

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQL, ilDBPdoMySQLGalera, ilDBPdoMySQLInnoDB, and ilDBPdoPostgreSQL.

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

1437 {
1438 return false;
1439 }

Referenced by supports().

+ Here is the caller graph for this function:

◆ tableColumnExists()

ilDBPdo::tableColumnExists (   $table_name,
  $column_name 
)
Parameters
$table_namestring
$column_namestring
Returns
bool

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

423 {
424 $fields = $this->loadModule(ilDBConstants::MODULE_MANAGER)->listTableFields($table_name);
425
426 $in_array = in_array($column_name, $fields);
427
428 return $in_array;
429 }

References loadModule(), and ilDBConstants\MODULE_MANAGER.

+ Here is the call graph for this function:

◆ tableExists()

ilDBPdo::tableExists (   $table_name)
Parameters
$table_namestring
Returns
bool

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

406 {
407 $result = $this->pdo->prepare("SHOW TABLES LIKE :table_name");
408 $result->execute(array('table_name' => $table_name));
409 $return = $result->rowCount();
410 $result->closeCursor();
411
412 return $return > 0;
413 }

References $result.

◆ uniqueConstraintExists()

ilDBPdo::uniqueConstraintExists (   $table,
array  $fields 
)
Parameters
$table
array$fields
Returns
bool

Implements ilDBPdoInterface.

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

1959 {
1960 $analyzer = new ilDBAnalyzer();
1961 $cons = $analyzer->getConstraintsInformation($table);
1962 foreach ($cons as $c) {
1963 if ($c["type"] == "unique" && count($fields) == count($c["fields"])) {
1964 $all_in = true;
1965 foreach ($fields as $f) {
1966 if (!isset($c["fields"][$f])) {
1967 $all_in = false;
1968 }
1969 }
1970 if ($all_in) {
1971 return true;
1972 }
1973 }
1974 }
1975
1976 return false;
1977 }

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

◆ unixTimestamp()

ilDBPdo::unixTimestamp ( )
Returns
string

Implements ilDBPdoInterface.

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

2017 {
2018 return "UNIX_TIMESTAMP()";
2019 }

◆ unlockTables()

ilDBPdo::unlockTables ( )
Deprecated:
Use ilAtomQuery instead
Exceptions

ilDatabaseException

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

1016 {
1017 $this->pdo->exec($this->manager->getQueryUtils()->unlock());
1018 }

◆ update()

ilDBPdo::update (   $table_name,
  $columns,
  $where 
)
Parameters
$table_namestring
$valuesarray
$wherearray
Returns
int|void

Implements ilDBInterface.

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

653 {
654 $fields = array();
655 $field_values = array();
656 $placeholders = array();
657 $placeholders_full = array();
658 $types = array();
659 $values = array();
660 $lobs = false;
661 $lob = array();
662 foreach ($columns as $k => $col) {
663 $field_value = $col[1];
664 $fields[] = $k;
665 $placeholders[] = "%s";
666 $placeholders_full[] = ":$k";
667 $types[] = $col[0];
668
669 if ($col[0] == "blob" || $col[0] == "clob" || $col[0] == 'text') {
670 $field_value = $this->sanitizeMB4StringIfNotSupported($field_value);
671 }
672
673 // integer auto-typecast (this casts bool values to integer)
674 if ($col[0] == 'integer' && !is_null($field_value)) {
675 $field_value = (int) $field_value;
676 }
677
678 $values[] = $field_value;
679 $field_values[$k] = $field_value;
680 if ($col[0] == "blob" || $col[0] == "clob") {
681 $lobs = true;
682 $lob[$k] = $k;
683 }
684 }
685
686 if ($lobs) {
687 $q = "UPDATE " . $this->quoteIdentifier($table_name) . " SET ";
688 $lim = "";
689 foreach ($fields as $k => $field) {
690 $q .= $lim . $field . " = " . $placeholders_full[$k];
691 $lim = ", ";
692 }
693 $q .= " WHERE ";
694 $lim = "";
695 foreach ($where as $k => $col) {
696 $q .= $lim . $k . " = " . $this->quote($col[1], $col[0]);
697 $lim = " AND ";
698 }
699
700 $r = $this->prepareManip($q, $types);
701 $this->execute($r, $field_values);
702 $this->free($r);
703 } else {
704 foreach ($where as $k => $col) {
705 $types[] = $col[0];
706 $values[] = $col[1];
707 $field_values[$k] = $col;
708 }
709 $q = "UPDATE " . $this->quoteIdentifier($table_name) . " SET ";
710 $lim = "";
711 foreach ($fields as $k => $field) {
712 $q .= $lim . $this->quoteIdentifier($field) . " = " . $placeholders[$k];
713 $lim = ", ";
714 }
715 $q .= " WHERE ";
716 $lim = "";
717 foreach ($where as $k => $col) {
718 $q .= $lim . $k . " = %s";
719 $lim = " AND ";
720 }
721
722 $r = $this->manipulateF($q, $types, $values);
723 }
724
725 return $r;
726 }
prepareManip($query, $types=null)

References $columns, ilDBInterface\execute(), ilDBInterface\free(), manipulateF(), prepareManip(), quote(), quoteIdentifier(), and sanitizeMB4StringIfNotSupported().

+ Here is the call graph for this function:

◆ upper()

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

Implements ilDBInterface.

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

1332 {
1333 return " UPPER(" . $a_exp . ") ";
1334 }

◆ useSlave()

ilDBPdo::useSlave (   $bool)
Parameters
$bool
Returns
bool

TODO

Implements ilDBInterface.

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

1085 {
1086 return false;
1087 }

Field Documentation

◆ $attributes

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

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

Referenced by addTableColumn(), and getAttributes().

◆ $charset

ilDBPdo::$charset = 'utf8'
protected

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

Referenced by generateDSN(), getCharset(), and setCharset().

◆ $db_type

ilDBPdo::$db_type = ''
protected

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

Referenced by getDBType().

◆ $dbname

ilDBPdo::$dbname = ''
protected

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

Referenced by generateDSN(), getDbname(), and setDbname().

◆ $dsn

ilDBPdo::$dsn = ''
protected

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

Referenced by getDSN().

◆ $error_code

ilDBPdo::$error_code = 0
protected

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

Referenced by getLastErrorCode().

◆ $field_definition

ilDBPdo::$field_definition
protected

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

Referenced by getFieldDefinition(), modifyTableColumn(), and setFieldDefinition().

◆ $host

ilDBPdo::$host = ''
protected

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

Referenced by generateDSN(), getHost(), setDBHost(), and setHost().

◆ $limit

ilDBPdo::$limit = null
protected

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

Referenced by appendLimit(), and setLimit().

◆ $manager

ilDBPdo::$manager
protected

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

Referenced by addUniqueConstraint(), and loadModule().

◆ $offset

ilDBPdo::$offset = null
protected

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

Referenced by ilDBPdoPostgreSQL\appendLimit(), and setLimit().

◆ $password

ilDBPdo::$password = ''
protected

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

Referenced by getPassword(), setDBPassword(), and setPassword().

◆ $pdo

ilDBPdo::$pdo
protected

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

◆ $port

ilDBPdo::$port = 3306
protected

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

Referenced by generateDSN(), getPort(), setDBPort(), and setPort().

◆ $reverse

ilDBPdo::$reverse
protected

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

Referenced by loadModule().

◆ $storage_engine

ilDBPdo::$storage_engine = 'MyISAM'
protected

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

Referenced by getStorageEngine(), and setStorageEngine().

◆ $username

ilDBPdo::$username = ''
protected

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

Referenced by getUsername(), and setUsername().

◆ FEATURE_FULLTEXT

const ilDBPdo::FEATURE_FULLTEXT = 'fulltext'

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

Referenced by supports().

◆ FEATURE_SLAVE

const ilDBPdo::FEATURE_SLAVE = 'slave'

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

Referenced by supports().

◆ FEATURE_TRANSACTIONS

const ilDBPdo::FEATURE_TRANSACTIONS = 'transactions'

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

Referenced by supports().


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