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

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::MDB2_AUTOQUERY_INSERT, $where=false, $types=null, $result_types=ilDBConstants::MDB2_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 909 of file class.ilDBPdo.php.

910 {
911 $i_name = $this->constraintName($a_table, $a_name) . "_idx";
912 $f_str = implode($a_fields, ",");
913 $q = "ALTER TABLE $a_table ADD FULLTEXT $i_name ($f_str)";
914 $this->query($q);
915 }
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 877 of file class.ilDBPdo.php.

878 {
879 assert(is_array($fields));
880 $this->field_definition->checkIndexName($index_name);
881
882 $definition_fields = array();
883 foreach ($fields as $f) {
884 $definition_fields[$f] = array();
885 }
886 $definition = array(
887 'fields' => $definition_fields,
888 );
889
890 if (!$fulltext) {
891 $this->manager->createIndex($table_name, $this->constraintName($table_name, $index_name), $definition);
892 } else {
893 if ($this->supportsFulltext()) {
894 $this->addFulltextIndex($table_name, $fields, $index_name); // TODO
895 }
896 }
897
898 return true;
899 }
addFulltextIndex($a_table, $a_fields, $a_name="in")

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

369 {
370 assert(is_array($primary_keys));
371
372 $fields = array();
373 foreach ($primary_keys as $f) {
374 $fields[$f] = array();
375 }
376 $definition = array(
377 'primary' => true,
378 'fields' => $fields,
379 );
380 $this->manager->createConstraint($table_name, $this->constraintName($table_name, $this->getPrimaryKeyIdentifier()), $definition);
381
382 return true;
383 }
getPrimaryKeyIdentifier()

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

466 {
467 if (!$this->checkColumnName($column_name)) {
468 throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
469 }
470 if (!$this->checkColumnDefinition($attributes)) {
471 throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
472 }
473
474 $changes = array(
475 "add" => array(
476 $column_name => $attributes,
477 ),
478 );
479
480 return $this->manager->alterTable($table_name, $changes, false);
481 }
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 1898 of file class.ilDBPdo.php.

1899 {
1900 assert(is_array($fields));
1902
1903 // check index name
1904 if (!$this->checkIndexName($name)) {
1905 throw new ilDatabaseException("ilDB Error: addUniqueConstraint(" . $table . "," . $name . ")");
1906 }
1907
1908 $fields_corrected = array();
1909 foreach ($fields as $f) {
1910 $fields_corrected[$f] = array();
1911 }
1912 $definition = array(
1913 'unique' => true,
1914 'fields' => $fields_corrected,
1915 );
1916
1917 return $manager->createConstraint($table, $this->constraintName($table, $name), $definition);
1918 }
checkIndexName($name)
if($format !==null) $name
Definition: metadata.php:146
if(empty($password)) $table
Definition: pwgen.php:24

References $manager, $name, $table, 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 1553 of file class.ilDBPdo.php.

1554 {
1555 if ($this->limit !== null && $this->offset !== null) {
1556 $query .= ' LIMIT ' . (int) $this->offset . ', ' . (int) $this->limit;
1557 $this->limit = null;
1558 $this->offset = null;
1559
1560 return $query;
1561 }
1562
1563 return $query;
1564 }
$query

References $limit, and $query.

Referenced by query().

+ Here is the caller graph for this function:

◆ autoExecute()

ilDBPdo::autoExecute (   $tablename,
  $fields,
  $mode = ilDBConstants::MDB2_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::MDB2_AUTOQUERY_INSERT ilDBConstants::MDB2_AUTOQUERY_UPDATE ilDBConstants::MDB2_AUTOQUERY_DELETE ilDBConstants::MDB2_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 2064 of file class.ilDBPdo.php.

2065 {
2066 $fields_values = (array) $fields;
2068 if (!empty($fields_values)) {
2069 $keys = $fields_values;
2070 } else {
2071 $keys = array();
2072 }
2073 } else {
2074 $keys = array_keys($fields_values);
2075 }
2076 $params = array_values($fields_values);
2077 if (empty($params)) {
2078 $query = $this->buildManipSQL($tablename, $keys, $mode, $where);
2079 $result = $this->pdo->query($query);
2080 } else {
2081 $stmt = $this->autoPrepare($tablename, $keys, $mode, $where, $types, $result_types);
2082 $this->execute($stmt);
2083 $this->free($stmt);
2084 $result = $stmt;
2085 }
2086
2087 return $result;
2088 }
$result
buildManipSQL($table, $table_fields, $mode, $where=false)
autoPrepare($table, $table_fields, $mode=ilDBConstants::MDB2_AUTOQUERY_INSERT, $where=false, $types=null, $result_types=ilDBConstants::MDB2_PREPARE_MANIP)
execute($stmt, $data=array())
$keys
$params
Definition: disable.php:11

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

+ Here is the call graph for this function:

◆ autoPrepare()

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

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

2101 {
2102 $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
2103
2104 return $this->prepare($query, $types, $result_types);
2105 }
prepare($query, $types=null, $result_types=null)

References $query, $table, 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 1697 of file class.ilDBPdo.php.

1698 {
1699 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1700 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1701 }
1702
1703 return $this->pdo->beginTransaction();
1704 }
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 1971 of file class.ilDBPdo.php.

1972 {
1973 require_once('./Services/Database/classes/Atom/class.ilAtomQueryLock.php');
1974
1975 return new ilAtomQueryLock($this);
1976 }
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 2116 of file class.ilDBPdo.php.

2117 {
2118 if ($this->options['quote_identifier']) {
2119 $table = $this->quoteIdentifier($table);
2120 }
2121
2122 if (!empty($table_fields) && $this->options['quote_identifier']) {
2123 foreach ($table_fields as $key => $field) {
2124 $table_fields[$key] = $this->quoteIdentifier($field);
2125 }
2126 }
2127
2128 if ($where !== false && !is_null($where)) {
2129 if (is_array($where)) {
2130 $where = implode(' AND ', $where);
2131 }
2132 $where = ' WHERE ' . $where;
2133 }
2134
2135 switch ($mode) {
2137 if (empty($table_fields)) {
2138 throw new ilDatabaseException('Insert requires table fields');
2139 }
2140 $cols = implode(', ', $table_fields);
2141 $values = '?' . str_repeat(', ?', (count($table_fields) - 1));
2142
2143 return 'INSERT INTO ' . $table . ' (' . $cols . ') VALUES (' . $values . ')';
2144 break;
2146 if (empty($table_fields)) {
2147 throw new ilDatabaseException('Update requires table fields');
2148 }
2149 $set = implode(' = ?, ', $table_fields) . ' = ?';
2150 $sql = 'UPDATE ' . $table . ' SET ' . $set . $where;
2151
2152 return $sql;
2153 break;
2155 $sql = 'DELETE FROM ' . $table . $where;
2156
2157 return $sql;
2158 break;
2160 $cols = !empty($table_fields) ? implode(', ', $table_fields) : '*';
2161 $sql = 'SELECT ' . $cols . ' FROM ' . $table . $where;
2162
2163 return $sql;
2164 break;
2165 }
2166
2167 throw new ilDatabaseException('Syntax error');
2168 }
quoteIdentifier($identifier, $check_option=false)
$key
Definition: croninfo.php:18
$cols
Definition: xhr_table.php:11

References $cols, $key, $table, ilDBConstants\MDB2_AUTOQUERY_DELETE, ilDBConstants\MDB2_AUTOQUERY_INSERT, ilDBConstants\MDB2_AUTOQUERY_SELECT, ilDBConstants\MDB2_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 2222 of file class.ilDBPdo.php.

2223 {
2224 return $this->manager->getQueryUtils()->cast($a_field_name, $a_dest_type);
2225 }

◆ checkColumn()

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

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

328 {
329 if (!$this->checkColumnName($a_col)) {
330 return false;
331 }
332
333 if (!$this->checkColumnDefinition($a_def)) {
334 return false;
335 }
336
337 return true;
338 }

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

347 {
348 return $this->field_definition->checkColumnDefinition($a_def);
349 }

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

357 {
358 return $this->field_definition->checkColumnName($a_name);
359 }

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

1886 {
1887 return $this->getFieldDefinition()->checkIndexName($name);
1888 }
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 310 of file class.ilDBPdo.php.

311 {
312 foreach ($a_cols as $col => $def) {
313 if (!$this->checkColumn($col, $def)) {
314 return false;
315 }
316 }
317
318 return true;
319 }
checkColumn($a_col, $a_def)
$def
Definition: croninfo.php:21

References $def, and 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 1673 of file class.ilDBPdo.php.

1674 {
1675 return $this->field_definition->checkTableName($a_name);
1676 }

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

1712 {
1713 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1714 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1715 }
1716
1717 return $this->pdo->commit();
1718 }

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

1544 {
1545 return $this->manager->getQueryUtils()->concat($values, $allow_null);
1546 }

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

102 {
103 $this->generateDSN();
104 try {
105 $options = $this->getAttributes();
106 $this->pdo = new PDO($this->getDSN(), $this->getUsername(), $this->getPassword(), $options);
107 $this->initHelpers();
108 $this->initSQLMode();
109 } catch (Exception $e) {
110 $this->error_code = $e->getCode();
111 if ($return_false_for_error) {
112 return false;
113 }
114 throw $e;
115 }
116
117 return ($this->pdo->errorCode() == PDO::ERR_NONE);
118 }
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
initHelpers()

References $options, 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, but they must be "globally" unique in oracle. (so this one is overwritten there)

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

970 {
971 return $a_constraint;
972 }

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
\PDOStatement
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

178 {
179 $this->setDbname(null);
180 $this->generateDSN();
181 $this->connect(true);
182 try {
183 return $this->query($this->manager->getQueryUtils()->createDatabase($a_name, $a_charset, $a_collation));
184 } catch (PDOException $e) {
185 return false;
186 }
187 }
connect($return_false_for_error=false)
setDbname($dbname)

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

421 {
422 $this->manager->createSequence($table_name, $start);
423 }

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

287 {
288 // check table name
289 if (!$this->checkTableName($table_name) && !$ignore_erros) {
290 throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
291 }
292
293 // check definition array
294 if (!$this->checkTableColumns($fields) && !$ignore_erros) {
295 throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
296 }
297
298 if ($drop_table) {
299 $this->dropTable($table_name, false);
300 }
301
302 return $this->manager->createTable($table_name, $fields, array());
303 }
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 2205 of file class.ilDBPdo.php.

2206 {
2207 return false;
2208 }

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

922 {
923 $i_name = $this->constraintName($a_table, $a_name) . "_idx";
924 $this->query("ALTER TABLE $a_table DROP FULLTEXT $i_name");
925 }

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

1741 {
1742 return $this->manager->dropIndex($a_table, $a_name);
1743 }

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

393 {
394 foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
395 $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
396 $idx_fields = array_keys((array) $def['fields']);
397
398 if ($idx_fields === $fields) {
399 return $this->dropIndex($table_name, $idx_name);
400 }
401 }
402
403 return false;
404 }
dropIndex($a_table, $a_name="i1")

References $def, and 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 2011 of file class.ilDBPdo.php.

2012 {
2013 return $this->manager->dropConstraint($table_name, "PRIMARY", true);
2014 }

◆ dropSequence()

ilDBPdo::dropSequence (   $table_name)
Parameters
$table_namestring

Implements ilDBInterface.

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

573 {
574 $this->manager->dropSequence($table_name);
575 }

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

491 {
492 $ilDBPdoManager = $this->loadModule(ilDBConstants::MODULE_MANAGER);
493 $tables = $ilDBPdoManager->listTables();
494 $table_exists = in_array($table_name, $tables);
495 if (!$table_exists && $error_if_not_existing) {
496 throw new ilDatabaseException("Table {$table_name} does not exist");
497 }
498
499 // drop sequence
500 $sequences = $ilDBPdoManager->listSequences();
501 if (in_array($table_name, $sequences)) {
502 $ilDBPdoManager->dropSequence($table_name);
503 }
504
505 // drop table
506 if ($table_exists) {
507 $ilDBPdoManager->dropTable($table_name);
508 }
509
510 return true;
511 }
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 584 of file class.ilDBPdo.php.

585 {
586 $changes = array(
587 "remove" => array(
588 $column_name => array(),
589 ),
590 );
591
592 return $this->manager->alterTable($table_name, $changes, false);
593 }

◆ dropUniqueConstraint()

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

Implements ilDBPdoInterface.

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

1927 {
1928 return $this->manager->dropConstraint($a_table, $this->constraintName($a_table, $a_name), false);
1929 }

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

1938 {
1939 $analyzer = new ilDBAnalyzer();
1940 $cons = $analyzer->getConstraintsInformation($a_table);
1941 foreach ($cons as $c) {
1942 if ($c["type"] == "unique" && count($a_fields) == count($c["fields"])) {
1943 $all_in = true;
1944 foreach ($a_fields as $f) {
1945 if (!isset($c["fields"][$f])) {
1946 $all_in = false;
1947 }
1948 }
1949 if ($all_in) {
1950 return $this->dropUniqueConstraint($a_table, $c['name']);
1951 }
1952 }
1953 }
1954
1955 return false;
1956 }
This class gives all kind of DB information using the MDB2 manager and reverse module.
dropUniqueConstraint($a_table, $a_name="con")

References dropUniqueConstraint().

+ Here is the call graph for this function:

◆ enableResultBuffering()

ilDBPdo::enableResultBuffering (   $a_status)
Parameters
$a_status

Implements ilDBInterface.

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

1416 {
1417 $this->pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $a_status);
1418 }

◆ equals()

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

Implements ilDBInterface.

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

1199 {
1200 if (!$emptyOrNull || $value != "") {
1201 return $columns . " = " . $this->quote($value, $type);
1202 } else {
1203 return "(" . $columns . " = '' OR $columns IS NULL)";
1204 }
1205 }
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 1827 of file class.ilDBPdo.php.

1828 {
1829 return $value;
1830 }

◆ escapePattern()

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

Implements ilDBPdoInterface.

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

1838 {
1839 return $text;
1840 }
$text
Definition: errorreport.php:18

References $text.

◆ executeMultiple()

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

Implements ilDBPdoInterface.

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

2022 {
2023 for ($i = 0, $j = count($a_data); $i < $j; $i++) {
2024 $stmt->execute($a_data[$i]);
2025 }
2026 }
$i
Definition: disco.tpl.php:19

References $i.

◆ fetchAssoc()

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

Implements ilDBInterface.

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

788 {
789 $res = $query_result->fetch(PDO::FETCH_ASSOC);
790 if ($res == null) {
791 $query_result->closeCursor();
792
793 return null;
794 }
795
796 return $res;
797 }
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 659 of file class.ilDBPdo.php.

660 {
661 $res = $query_result->fetchObject();
662 if ($res == null) {
663 $query_result->closeCursor();
664
665 return null;
666 }
667
668 return $res;
669 }

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

2035 {
2036 return "FROM_UNIXTIME(" . $a_expr . ")";
2037 }

◆ generateDSN()

ilDBPdo::generateDSN ( )

Reimplemented in ilDBPdoPostgreSQL.

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

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

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

147 {
148 return array();
149 }

Referenced by getAttributes().

+ Here is the caller graph for this function:

◆ getAllowedAttributes()

ilDBPdo::getAllowedAttributes ( )

Returns
array

Implements ilDBInterface.

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

1514 {
1515 return $this->field_definition->getAllowedAttributes();
1516 }

◆ getAttributes()

ilDBPdo::getAttributes ( )
protected
Returns
array

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

133 {
135 foreach ($this->getAdditionalAttributes() as $k => $v) {
136 $options[$k] = $v;
137 }
138
139 return $options;
140 }
getAdditionalAttributes()

References $attributes, $options, 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 1247 of file class.ilDBPdo.php.

1248 {
1249 return $this->charset;
1250 }

References $charset.

Referenced by generateDSN().

+ Here is the caller graph for this function:

◆ getDbname()

ilDBPdo::getDbname ( )
Returns
string

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

1230 {
1231 return $this->dbname;
1232 }

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

988 {
989 return $this->db_type;
990 }

References $db_type.

◆ getDBVersion()

ilDBPdo::getDBVersion ( )
Returns
string
Exceptions
ilDatabaseException

Implements ilDBPdoInterface.

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

2176 {
2177 $d = $this->fetchObject($this->query("SELECT VERSION() AS version"));
2178
2179 return ($d->version ? $d->version : 'Unknown');
2180 }
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 978 of file class.ilDBPdo.php.

979 {
980 return $this->dsn;
981 }

References $dsn.

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

+ Here is the caller graph for this function:

◆ getFieldDefinition()

ilDBPdo::getFieldDefinition ( )
Returns
ilDBPdoFieldDefinition

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

156 {
158 }

References $field_definition.

Referenced by checkIndexName().

+ Here is the caller graph for this function:

◆ getHost()

ilDBPdo::getHost ( )
Returns
string

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

1212 {
1213 return $this->host;
1214 }

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

949 {
950 return sprintf(ilDBPdoFieldDefinition::INDEX_FORMAT, preg_replace('/[^a-z0-9_\$]/i', '_', $index_name_base));
951 }
sprintf('%.4f', $callTime)

References ilDBPdoFieldDefinition\INDEX_FORMAT, and sprintf.

◆ getLastErrorCode()

ilDBPdo::getLastErrorCode ( )
Returns
int

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

194 {
195 if ($this->pdo instanceof PDO) {
196 return $this->pdo->errorCode();
197 }
198
199 return $this->error_code;
200 }

References $error_code.

◆ getLastInsertId()

ilDBPdo::getLastInsertId ( )
Returns
string

Implements ilDBPdoInterface.

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

1963 {
1964 return $this->pdo->lastInsertId();
1965 }

◆ getPassword()

ilDBPdo::getPassword ( )
Returns
string

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

1284 {
1285 return $this->password;
1286 }

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

1302 {
1303 return $this->port;
1304 }

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

411 {
412 return "PRIMARY";
413 }

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

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

References ilDBPdoFieldDefinition\SEQUENCE_FORMAT, and sprintf.

Referenced by ilDBPdoMySQL\nextId().

+ Here is the caller graph for this function:

◆ getServerVersion()

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

Implements ilDBPdoInterface.

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

1817 {
1818 return $this->pdo->query('SELECT VERSION()')->fetchColumn();
1819 }

◆ getStorageEngine()

ilDBPdo::getStorageEngine ( )
Returns
string

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

1759 {
1760 return $this->storage_engine;
1761 }

References $storage_engine.

◆ getUsername()

ilDBPdo::getUsername ( )
Returns
string

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

1266 {
1267 return $this->username;
1268 }

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

2215 {
2216 return $this->manager->getQueryUtils()->groupConcat($a_field_name, $a_seperator, $a_order);
2217 }

◆ in()

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

Implements ilDBInterface.

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

1054 {
1055 return $this->manager->getQueryUtils()->in($field, $values, $negate, $type);
1056 }

References $type.

◆ indexExistsByFields()

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

Implements ilDBInterface.

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

857 {
858 foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
859 $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
860 $idx_fields = array_keys((array) $def['fields']);
861
862 if ($idx_fields === $fields) {
863 return true;
864 }
865 }
866
867 return false;
868 }

References $def.

◆ initFromIniFile()

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

Implements ilDBInterface.

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

207 {
208 global $ilClientIniFile;
209 if ($tmpClientIniFile instanceof ilIniFile) {
210 $clientIniFile = $tmpClientIniFile;
211 } else {
212 $clientIniFile = $ilClientIniFile;
213 }
214
215 $this->setUsername($clientIniFile->readVariable("db", "user"));
216 $this->setHost($clientIniFile->readVariable("db", "host"));
217 $this->setPort((int) $clientIniFile->readVariable("db", "port"));
218 $this->setPassword($clientIniFile->readVariable("db", "pass"));
219 $this->setDbname($clientIniFile->readVariable("db", "name"));
220 $this->setDBType($clientIniFile->readVariable("db", "type"));
221
222 $this->generateDSN();
223 }
setUsername($username)
setDBType($type)
setPort($port)
setPassword($password)
setHost($host)
INIFile Parser.

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

125 {
126 }

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

637 {
638 $real = array();
639 $fields = array();
640 foreach ($values as $key => $val) {
641 $real[] = $this->quote($val[1], $val[0]);
642 $fields[] = $this->quoteIdentifier($key);
643 }
644 $values = implode(",", $real);
645 $fields = implode(",", $fields);
646 $query = "INSERT INTO " . $table_name . " (" . $fields . ") VALUES (" . $values . ")";
647
649
650 return $this->pdo->exec($query);
651 }
sanitizeMB4StringIfNotSupported($query)
string sanitized query

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

932 {
933 $set = $this->query("SHOW INDEX FROM " . $a_table);
934 while ($rec = $this->fetchAssoc($set)) {
935 if ($rec["Key_name"] == $a_name && $rec["Index_type"] == "FULLTEXT") {
936 return true;
937 }
938 }
939
940 return false;
941 }
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 1683 of file class.ilDBPdo.php.

1684 {
1685 require_once('./Services/Database/classes/PDO/FieldDefinition/class.ilDBPdoMySQLFieldDefinition.php');
1686 global $DIC;
1687 $ilDBPdoMySQLFieldDefinition = new ilDBPdoMySQLFieldDefinition($DIC['ilDB']);
1688
1689 return $ilDBPdoMySQLFieldDefinition->isReserved($a_word);
1690 }
Class ilDBPdoMySQLFieldDefinition.
global $DIC
Definition: saml.php:7

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

1137 {
1138 return $this->manager->getQueryUtils()->like($column, $type, $value, $case_insensitive);
1139 }
$column
Definition: 39dropdown.php:62

References $column, and $type.

◆ listSequences()

ilDBPdo::listSequences ( )
Returns
array

Implements ilDBInterface.

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

1533 {
1534 return $this->manager->listSequences();
1535 }

Referenced by sequenceExists().

+ Here is the caller graph for this function:

◆ listTables()

ilDBPdo::listTables ( )
Returns
array

Implements ilDBInterface.

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

1490 {
1491 return $this->manager->listTables();
1492 }

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

1500 {
1501 switch ($module) {
1503 return $this->manager;
1505 return $this->reverse;
1506 }
1507 }
if($modEnd===false) $module
Definition: module.php:59

References $manager, $module, $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 1573 of file class.ilDBPdo.php.

1574 {
1575 return $this->manager->getQueryUtils()->locate($a_needle, $a_string, $a_start_pos);
1576 }

◆ lockTables()

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

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

1023 {
1024 assert(is_array($tables));
1025
1026 $lock = $this->manager->getQueryUtils()->lock($tables);
1027 global $ilLog;
1028 if ($ilLog instanceof ilLog) {
1029 $ilLog->write('ilDB::lockTables(): ' . $lock);
1030 }
1031
1032 $this->pdo->exec($lock);
1033 }
logging
Definition: class.ilLog.php:19

References $ilLog.

◆ lower()

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

Implements ilDBInterface.

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

1367 {
1368 return " LOWER(" . $a_exp . ") ";
1369 }

◆ manipulate()

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

ilDatabaseException

Implements ilDBInterface.

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

762 {
763 global $DIC;
764 $ilBench = $DIC['ilBench'];
765 try {
767 if ($ilBench instanceof ilBenchmark) {
768 $ilBench->startDbBench($query);
769 }
770 $r = $this->pdo->exec($query);
771 if ($ilBench instanceof ilBenchmark) {
772 $ilBench->stopDbBench();
773 }
774 } catch (PDOException $e) {
775 throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query);
776 }
777
778 return $r;
779 }
performance measurement class
$r
Definition: example_031.php:79
global $ilBench
Definition: ilias.php:18

References $DIC, $ilBench, $query, $r, 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 1088 of file class.ilDBPdo.php.

1089 {
1090 if (!is_array($types) || !is_array($values) || count($types) != count($values)) {
1091 throw new ilDatabaseException("ilDB::manipulateF: types and values must be arrays of same size. ($query)");
1092 }
1093 $quoted_values = array();
1094 foreach ($types as $k => $t) {
1095 $quoted_values[] = $this->quote($values[$k], $t);
1096 }
1097 $query = vsprintf($query, $quoted_values);
1098
1099 return $this->manipulate($query);
1100 }
manipulate($query)

References $query, $t, 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 1856 of file class.ilDBPdo.php.

1857 {
1858 return array();
1859 }

◆ migrateAllTablesToEngine()

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

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoMySQL.

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

1848 {
1849 return array();
1850 }

◆ modifyTableColumn()

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

ilDatabaseException

Implements ilDBInterface.

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

1587 {
1588 $def = $this->reverse->getTableFieldDefinition($table, $a_column);
1589
1590 $analyzer = new ilDBAnalyzer($this);
1591 $best_alt = $analyzer->getBestDefinitionAlternative($def);
1592 $def = $def[$best_alt];
1593 unset($def["nativetype"]);
1594 unset($def["mdb2type"]);
1595
1596 // check attributes
1597 $ilDBPdoFieldDefinition = $this->field_definition;
1598
1599 $type = ($a_attributes["type"] != "") ? $a_attributes["type"] : $def["type"];
1600 foreach ($def as $k => $v) {
1601 if ($k != "type" && !$ilDBPdoFieldDefinition->isAllowedAttribute($k, $type)) {
1602 unset($def[$k]);
1603 }
1604 }
1605 $check_array = $def;
1606 foreach ($a_attributes as $k => $v) {
1607 $check_array[$k] = $v;
1608 }
1609 if (!$this->checkColumnDefinition($check_array, true)) {
1610 throw new ilDatabaseException("ilDB Error: modifyTableColumn(" . $table . ", " . $a_column . ")");
1611 }
1612
1613 foreach ($a_attributes as $a => $v) {
1614 $def[$a] = $v;
1615 }
1616
1617 $a_attributes["definition"] = $def;
1618
1619 $changes = array(
1620 "change" => array(
1621 $a_column => $a_attributes,
1622 ),
1623 );
1624
1625 return $this->manager->alterTable($table, $changes, false);
1626 }

References $def, $field_definition, $table, $type, and checkColumnDefinition().

+ Here is the call graph for this function:

◆ nextId()

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

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQL, and ilDBPdoPostgreSQL.

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

252 {
253 $sequence_table_name = $table_name . '_seq';
254
255 $last_insert_id = $this->pdo->lastInsertId($table_name);
256 if ($last_insert_id) {
257 // return $last_insert_id;
258 }
259
260 if ($this->tableExists($sequence_table_name)) {
261 $stmt = $this->pdo->prepare("SELECT sequence FROM $sequence_table_name");
262 $stmt->execute();
263 $rows = $stmt->fetch(PDO::FETCH_ASSOC);
264 $stmt->closeCursor();
265 $next_id = $rows['sequence'] + 1;
266 $stmt = $this->pdo->prepare("DELETE FROM $sequence_table_name");
267 $stmt->execute(array("next_id" => $next_id));
268 $stmt = $this->pdo->prepare("INSERT INTO $sequence_table_name (sequence) VALUES (:next_id)");
269 $stmt->execute(array("next_id" => $next_id));
270
271 return $next_id;
272 }
273
274 return 1;
275 }
tableExists($table_name)
$rows
Definition: xhr_table.php:10

References $rows, and tableExists().

+ Here is the call graph for this function:

◆ now()

ilDBPdo::now ( )
Returns
string the now statement

Implements ilDBInterface.

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

1146 {
1147 return $this->manager->getQueryUtils()->now();
1148 }

◆ numRows()

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

Implements ilDBInterface.

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

806 {
807 return $query_result->rowCount();
808 }

◆ prepare()

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

Implements ilDBInterface.

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

1407 {
1408 return new ilPDOStatement($this->pdo->prepare($query));
1409 }
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 1394 of file class.ilDBPdo.php.

1395 {
1396 return new ilPDOStatement($this->pdo->prepare($query));
1397 }

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

521 {
522 global $DIC;
523 $ilBench = $DIC['ilBench'];
524
525 $query = $this->appendLimit($query);
526
527 try {
528 if ($ilBench instanceof ilBenchmark) {
529 $ilBench->startDbBench($query);
530 }
531 $res = $this->pdo->query($query);
532 if ($ilBench instanceof ilBenchmark) {
533 $ilBench->stopDbBench();
534 }
535 } catch (PDOException $e) {
536 throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query);
537 }
538
539 $err = $this->pdo->errorCode();
540 if ($err != PDO::ERR_NONE) {
541 $info = $this->pdo->errorInfo();
542 $info_message = $info[2];
543 throw new ilDatabaseException($info_message . ' QUERY: ' . $query);
544 }
545
546 return new ilPDOStatement($res);
547 }
appendLimit($query)
$info
Definition: index.php:5

References $DIC, $ilBench, $info, $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 1770 of file class.ilDBPdo.php.

1771 {
1772 switch ($type) {
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, PDO::FETCH_ASSOC)->fetchAll(PDO::FETCH_COLUMN, $colnum);
1785 }

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
\PDOStatement
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

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

References $query, $t, 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 1794 of file class.ilDBPdo.php.

1795 {
1796 switch ($fetchmode) {
1798 $type = PDO::FETCH_ASSOC;
1799 break;
1801 $type = PDO::FETCH_OBJ;
1802 break;
1803 default:
1804 $type = PDO::FETCH_ASSOC;
1805 break;
1806 }
1807
1808 return $this->pdo->query($query, $type)->fetch();
1809 }

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

818 {
819 if ($value === null) {
820 return 'NULL';
821 }
822
823 $pdo_type = PDO::PARAM_STR;
824 switch ($type) {
828 if ($value === '') {
829 return 'NULL';
830 }
831 break;
833 $value = (int) $value;
834
835 return $value;
836 break;
838 $pdo_type = PDO::PARAM_INT;
839 break;
841 default:
842 $pdo_type = PDO::PARAM_STR;
843 break;
844 }
845
846 return $this->pdo->quote($value, $pdo_type);
847 }

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

241 {
242 return '`' . $identifier . '`';
243 }

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

1649 {
1650 // check table name
1651 try {
1652 $this->checkTableName($a_new_name);
1653 } catch (ilDatabaseException $e) {
1654 throw new ilDatabaseException("ilDB Error: renameTable(" . $a_name . "," . $a_new_name . ")<br />" . $e->getMessage());
1655 }
1656
1657 $this->manager->alterTable($a_name, array("name" => $a_new_name), false);
1658
1659 // The abstraction_progress is no longer used in ILIAS, see http://www.ilias.de/mantis/view.php?id=19513
1660 // $query = "UPDATE abstraction_progress " . "SET table_name = " . $this->quote($a_new_name, 'text') . " " . "WHERE table_name = "
1661 // . $this->quote($a_name, 'text');
1662 // $this->pdo->query($query);
1663
1664 return true;
1665 }

References checkTableName().

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

604 {
605 // check table name
606 if (!$this->checkColumnName($column_new_name)) {
607 throw new ilDatabaseException("ilDB Error: renameTableColumn(" . $table_name . "," . $column_old_name . "," . $column_new_name . ")");
608 }
609
610 $def = $this->reverse->getTableFieldDefinition($table_name, $column_old_name);
611
612 $analyzer = new ilDBAnalyzer($this);
613 $best_alt = $analyzer->getBestDefinitionAlternative($def);
614 $def = $def[$best_alt];
615 unset($def["nativetype"]);
616 unset($def["mdb2type"]);
617
618 $f["definition"] = $def;
619 $f["name"] = $column_new_name;
620
621 $changes = array(
622 "rename" => array(
623 $column_old_name => $f,
624 ),
625 );
626
627 return $this->manager->alterTable($table_name, $changes, false);
628 }

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

1160 {
1161 $a_columns = array_merge($primaryKeys, $otherColumns);
1162 $fields = array();
1163 $field_values = array();
1164 $placeholders = array();
1165 $types = array();
1166 $values = array();
1167
1168 foreach ($a_columns as $k => $col) {
1169 $fields[] = $k;
1170 $placeholders[] = "%s";
1171 $placeholders2[] = ":$k";
1172 $types[] = $col[0];
1173
1174 // integer auto-typecast (this casts bool values to integer)
1175 if ($col[0] == 'integer' && !is_null($col[1])) {
1176 $col[1] = (int) $col[1];
1177 }
1178
1179 $values[] = $col[1];
1180 $field_values[$k] = $col[1];
1181 }
1182
1183 $q = "REPLACE INTO " . $table . " (" . implode($fields, ",") . ") VALUES (" . implode($placeholders, ",") . ")";
1184
1185 $r = $this->manipulateF($q, $types, $values);
1186
1187 return $r;
1188 }
manipulateF($query, $types, $values)

References $r, $table, and manipulateF().

+ Here is the call graph for this function:

◆ rollback()

ilDBPdo::rollback ( )
Returns
bool
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

1726 {
1727 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1728 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1729 }
1730
1731 return $this->pdo->rollBack();
1732 }

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

2187 {
2188 if (!$this->doesCollationSupportMB4Strings()) {
2189 $query_replaced = preg_replace(
2190 '/[\x{10000}-\x{10FFFF}]/u',
2192 $query
2193 );
2194 if (!empty($query_replaced)) {
2195 return $query_replaced;
2196 }
2197 }
2198
2199 return $query;
2200 }
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 1523 of file class.ilDBPdo.php.

1524 {
1525 return in_array($sequence, $this->listSequences());
1526 }

References listSequences().

+ Here is the call graph for this function:

◆ setCharset()

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

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

1257 {
1258 $this->charset = $charset;
1259 }

References $charset.

◆ setDBHost()

ilDBPdo::setDBHost (   $host)
Parameters
$host

Implements ilDBInterface.

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

1347 {
1348 $this->setHost($host);
1349 }

References $host, and setHost().

+ Here is the call graph for this function:

◆ setDbname()

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

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

1239 {
1240 $this->dbname = $dbname;
1241 }

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

1338 {
1339 $this->setPassword($password);
1340 }

References $password, and setPassword().

+ Here is the call graph for this function:

◆ setDBPort()

ilDBPdo::setDBPort (   $port)
Parameters
$port

Implements ilDBInterface.

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

1329 {
1330 $this->setPort($port);
1331 }

References $port, and setPort().

+ Here is the call graph for this function:

◆ setDBType()

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

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

998 {
999 $this->db_type = $type;
1000 }

References $type.

Referenced by initFromIniFile().

+ Here is the caller graph for this function:

◆ setDBUser()

ilDBPdo::setDBUser (   $user)
Parameters
$user

Implements ilDBInterface.

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

1320 {
1321 $this->setUsername($user);
1322 }

References setUsername().

+ Here is the call graph for this function:

◆ setFieldDefinition()

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

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

165 {
166 $this->field_definition = $field_definition;
167 }

References $field_definition.

◆ setHost()

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

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

1221 {
1222 $this->host = $host;
1223 }

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

1122 {
1123 $this->limit = $limit;
1124 $this->offset = $offset;
1125 }

References $limit, and $offset.

◆ setPassword()

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

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

1293 {
1294 $this->password = $password;
1295 }

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

1311 {
1312 $this->port = $port;
1313 }

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

1750 {
1751 $this->storage_engine = $storage_engine;
1752 }

References $storage_engine.

◆ setUsername()

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

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

1275 {
1276 $this->username = $username;
1277 }

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

1379 {
1380 $lenstr = "";
1381 if ($a_len > -1) {
1382 $lenstr = ", " . $a_len;
1383 }
1384
1385 return " SUBSTR(" . $a_exp . ", " . $a_pos . $lenstr . ") ";
1386 }

◆ supports()

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

Implements ilDBInterface.

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

1472 {
1473 switch ($feature) {
1475 return $this->supportsTransactions();
1477 return $this->supportsFulltext();
1479 return $this->supportsSlave();
1480 default:
1481 return false;
1482 }
1483 }
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 1865 of file class.ilDBPdo.php.

1866 {
1867 return false;
1868 }

◆ supportsEngineMigration()

ilDBPdo::supportsEngineMigration ( )
Returns
bool

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoMySQL.

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

1875 {
1876 return false;
1877 }

◆ supportsFulltext()

ilDBPdo::supportsFulltext ( )
Returns
bool

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQLInnoDB, ilDBPdoMySQLMyISAM, and ilDBPdoPostgreSQL.

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

1453 {
1454 return false;
1455 }

Referenced by addIndex(), and supports().

+ Here is the caller graph for this function:

◆ supportsSlave()

ilDBPdo::supportsSlave ( )
Returns
bool

Implements ilDBInterface.

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

1444 {
1445 return false;
1446 }

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

1462 {
1463 return false;
1464 }

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

449 {
450 $fields = $this->loadModule(ilDBConstants::MODULE_MANAGER)->listTableFields($table_name);
451
452 $in_array = in_array($column_name, $fields);
453
454 return $in_array;
455 }

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

432 {
433 $result = $this->pdo->prepare("SHOW TABLES LIKE :table_name");
434 $result->execute(array('table_name' => $table_name));
435 $return = $result->rowCount();
436 $result->closeCursor();
437
438 return $return > 0;
439 }

References $result.

Referenced by nextId().

+ Here is the caller graph for this function:

◆ uniqueConstraintExists()

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

Implements ilDBPdoInterface.

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

1985 {
1986 require_once('./Services/Database/classes/class.ilDBAnalyzer.php');
1987 $analyzer = new ilDBAnalyzer();
1988 $cons = $analyzer->getConstraintsInformation($table);
1989 foreach ($cons as $c) {
1990 if ($c["type"] == "unique" && count($fields) == count($c["fields"])) {
1991 $all_in = true;
1992 foreach ($fields as $f) {
1993 if (!isset($c["fields"][$f])) {
1994 $all_in = false;
1995 }
1996 }
1997 if ($all_in) {
1998 return true;
1999 }
2000 }
2001 }
2002
2003 return false;
2004 }

References $table.

◆ unixTimestamp()

ilDBPdo::unixTimestamp ( )
Returns
string

Implements ilDBPdoInterface.

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

2044 {
2045 return "UNIX_TIMESTAMP()";
2046 }

◆ unlockTables()

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

ilDatabaseException

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

1041 {
1042 $this->pdo->exec($this->manager->getQueryUtils()->unlock());
1043 }

◆ update()

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

Implements ilDBInterface.

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

679 {
680 $fields = array();
681 $field_values = array();
682 $placeholders = array();
683 $placeholders_full = array();
684 $types = array();
685 $values = array();
686 $lobs = false;
687 $lob = array();
688 foreach ($columns as $k => $col) {
689 $field_value = $col[1];
690 $fields[] = $k;
691 $placeholders[] = "%s";
692 $placeholders_full[] = ":$k";
693 $types[] = $col[0];
694
695 if ($col[0] == "blob" || $col[0] == "clob" || $col[0] == 'text') {
696 $field_value = $this->sanitizeMB4StringIfNotSupported($field_value);
697 }
698
699 // integer auto-typecast (this casts bool values to integer)
700 if ($col[0] == 'integer' && !is_null($field_value)) {
701 $field_value = (int) $field_value;
702 }
703
704 $values[] = $field_value;
705 $field_values[$k] = $field_value;
706 if ($col[0] == "blob" || $col[0] == "clob") {
707 $lobs = true;
708 $lob[$k] = $k;
709 }
710 }
711
712 if ($lobs) {
713 $q = "UPDATE " . $table_name . " SET ";
714 $lim = "";
715 foreach ($fields as $k => $field) {
716 $q .= $lim . $field . " = " . $placeholders_full[$k];
717 $lim = ", ";
718 }
719 $q .= " WHERE ";
720 $lim = "";
721 foreach ($where as $k => $col) {
722 $q .= $lim . $k . " = " . $this->quote($col[1], $col[0]);
723 $lim = " AND ";
724 }
725
726 $r = $this->prepareManip($q, $types);
727 $this->execute($r, $field_values);
728 $this->free($r);
729 } else {
730 foreach ($where as $k => $col) {
731 $types[] = $col[0];
732 $values[] = $col[1];
733 $field_values[$k] = $col;
734 }
735 $q = "UPDATE " . $table_name . " SET ";
736 $lim = "";
737 foreach ($fields as $k => $field) {
738 $q .= $lim . $this->quoteIdentifier($field) . " = " . $placeholders[$k];
739 $lim = ", ";
740 }
741 $q .= " WHERE ";
742 $lim = "";
743 foreach ($where as $k => $col) {
744 $q .= $lim . $k . " = %s";
745 $lim = " AND ";
746 }
747
748 $r = $this->manipulateF($q, $types, $values);
749 }
750
751 return $r;
752 }
prepareManip($query, $types=null)

References $columns, $r, 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 1356 of file class.ilDBPdo.php.

1357 {
1358 return " UPPER(" . $a_exp . ") ";
1359 }

◆ useSlave()

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

TODO

Implements ilDBInterface.

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

1110 {
1111 return false;
1112 }

Field Documentation

◆ $attributes

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

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

Referenced by addTableColumn(), and getAttributes().

◆ $charset

ilDBPdo::$charset = 'utf8'
protected

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

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

◆ $db_type

ilDBPdo::$db_type = ''
protected

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

Referenced by getDBType().

◆ $dbname

ilDBPdo::$dbname = ''
protected

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

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

◆ $dsn

ilDBPdo::$dsn = ''
protected

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

Referenced by getDSN().

◆ $error_code

ilDBPdo::$error_code = 0
protected

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

Referenced by getLastErrorCode().

◆ $field_definition

ilDBPdo::$field_definition
protected

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

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

◆ $host

ilDBPdo::$host = ''
protected

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

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

◆ $limit

ilDBPdo::$limit = null
protected

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

Referenced by appendLimit(), and setLimit().

◆ $manager

ilDBPdo::$manager
protected

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

Referenced by addUniqueConstraint(), and loadModule().

◆ $offset

ilDBPdo::$offset = null
protected

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

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

◆ $password

ilDBPdo::$password = ''
protected

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

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

◆ $pdo

ilDBPdo::$pdo
protected

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

◆ $port

ilDBPdo::$port = 3306
protected

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

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

◆ $reverse

ilDBPdo::$reverse
protected

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

Referenced by loadModule().

◆ $storage_engine

ilDBPdo::$storage_engine = 'MyISAM'
protected

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

Referenced by getStorageEngine(), and setStorageEngine().

◆ $username

ilDBPdo::$username = ''
protected

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

Referenced by getUsername(), and setUsername().

◆ FEATURE_FULLTEXT

const ilDBPdo::FEATURE_FULLTEXT = 'fulltext'

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

Referenced by supports().

◆ FEATURE_SLAVE

const ilDBPdo::FEATURE_SLAVE = 'slave'

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

Referenced by supports().

◆ FEATURE_TRANSACTIONS

const ilDBPdo::FEATURE_TRANSACTIONS = 'transactions'

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

Referenced by supports().


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