ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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)
 
 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)
 
 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)
 
 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 869 of file class.ilDBPdo.php.

869 {
870 $i_name = $this->constraintName($a_table, $a_name) . "_idx";
871 $f_str = implode($a_fields, ",");
872 $q = "ALTER TABLE $a_table ADD FULLTEXT $i_name ($f_str)";
873 $this->query($q);
874 }
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 838 of file class.ilDBPdo.php.

838 {
839 assert(is_array($fields));
840 $this->field_definition->checkIndexName($index_name);
841
842 $definition_fields = array();
843 foreach ($fields as $f) {
844 $definition_fields[$f] = array();
845 }
846 $definition = array(
847 'fields' => $definition_fields,
848 );
849
850 if (!$fulltext) {
851 $this->manager->createIndex($table_name, $this->constraintName($table_name, $index_name), $definition);
852 } else {
853 if ($this->supportsFulltext()) {
854 $this->addFulltextIndex($table_name, $fields, $index_name); // TODO
855 }
856 }
857
858 return true;
859 }
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 351 of file class.ilDBPdo.php.

351 {
352 assert(is_array($primary_keys));
353
354 $fields = array();
355 foreach ($primary_keys as $f) {
356 $fields[$f] = array();
357 }
358 $definition = array(
359 'primary' => true,
360 'fields' => $fields,
361 );
362 $this->manager->createConstraint($table_name, $this->constraintName($table_name, $this->getPrimaryKeyIdentifier()), $definition);
363
364 return true;
365 }
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 442 of file class.ilDBPdo.php.

442 {
443 if (!$this->checkColumnName($column_name)) {
444 throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
445 }
446 if (!$this->checkColumnDefinition($attributes)) {
447 throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
448 }
449
450 $changes = array(
451 "add" => array(
452 $column_name => $attributes,
453 ),
454 );
455
456 return $this->manager->alterTable($table_name, $changes, false);
457 }
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 1781 of file class.ilDBPdo.php.

1781 {
1782 assert(is_array($fields));
1784
1785 // check index name
1786 if (!$this->checkIndexName($name)) {
1787 throw new ilDatabaseException("ilDB Error: addUniqueConstraint(" . $table . "," . $name . ")");
1788 }
1789
1790 $fields_corrected = array();
1791 foreach ($fields as $f) {
1792 $fields_corrected[$f] = array();
1793 }
1794 $definition = array(
1795 'unique' => true,
1796 'fields' => $fields_corrected,
1797 );
1798
1799 return $manager->createConstraint($table, $this->constraintName($table, $name), $definition);
1800 }
checkIndexName($name)

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

1459 {
1460 if ($this->limit !== null && $this->offset !== null) {
1461 $query .= ' LIMIT ' . (int)$this->offset . ', ' . (int)$this->limit;
1462 $this->limit = null;
1463 $this->offset = null;
1464
1465 return $query;
1466 }
1467
1468 return $query;
1469 }

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

1937 {
1938 $fields_values = (array)$fields;
1940 if (!empty($fields_values)) {
1941 $keys = $fields_values;
1942 } else {
1943 $keys = array();
1944 }
1945 } else {
1946 $keys = array_keys($fields_values);
1947 }
1948 $params = array_values($fields_values);
1949 if (empty($params)) {
1950 $query = $this->buildManipSQL($tablename, $keys, $mode, $where);
1951 $result = $this->pdo->query($query);
1952 } else {
1953 $stmt = $this->autoPrepare($tablename, $keys, $mode, $where, $types, $result_types);
1954 $this->execute($stmt);
1955 $this->free($stmt);
1956 $result = $stmt;
1957 }
1958
1959 return $result;
1960 }
$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)
$params
Definition: example_049.php:96
execute($stmt, $data=array())

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

1972 {
1973 $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
1974
1975 return $this->prepare($query, $types, $result_types);
1976 }
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 1596 of file class.ilDBPdo.php.

1596 {
1597 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1598 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1599 }
1600
1601 return $this->pdo->beginTransaction();
1602 }
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 1850 of file class.ilDBPdo.php.

1850 {
1851 require_once('./Services/Database/classes/Atom/class.ilAtomQueryLock.php');
1852
1853 return new ilAtomQueryLock($this);
1854 }
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 1987 of file class.ilDBPdo.php.

1987 {
1988 if ($this->options['quote_identifier']) {
1989 $table = $this->quoteIdentifier($table);
1990 }
1991
1992 if (!empty($table_fields) && $this->options['quote_identifier']) {
1993 foreach ($table_fields as $key => $field) {
1994 $table_fields[$key] = $this->quoteIdentifier($field);
1995 }
1996 }
1997
1998 if ($where !== false && !is_null($where)) {
1999 if (is_array($where)) {
2000 $where = implode(' AND ', $where);
2001 }
2002 $where = ' WHERE ' . $where;
2003 }
2004
2005 switch ($mode) {
2007 if (empty($table_fields)) {
2008 throw new ilDatabaseException('Insert requires table fields');
2009 }
2010 $cols = implode(', ', $table_fields);
2011 $values = '?' . str_repeat(', ?', (count($table_fields) - 1));
2012
2013 return 'INSERT INTO ' . $table . ' (' . $cols . ') VALUES (' . $values . ')';
2014 break;
2016 if (empty($table_fields)) {
2017 throw new ilDatabaseException('Update requires table fields');
2018 }
2019 $set = implode(' = ?, ', $table_fields) . ' = ?';
2020 $sql = 'UPDATE ' . $table . ' SET ' . $set . $where;
2021
2022 return $sql;
2023 break;
2025 $sql = 'DELETE FROM ' . $table . $where;
2026
2027 return $sql;
2028 break;
2030 $cols = !empty($table_fields) ? implode(', ', $table_fields) : '*';
2031 $sql = 'SELECT ' . $cols . ' FROM ' . $table . $where;
2032
2033 return $sql;
2034 break;
2035 }
2036
2037 throw new ilDatabaseException('Syntax error');
2038 }
quoteIdentifier($identifier, $check_option=false)

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

2088 {
2089 return $this->manager->getQueryUtils()->cast($a_field_name, $a_dest_type);
2090 }

◆ checkColumn()

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

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

313 {
314 if (!$this->checkColumnName($a_col)) {
315 return false;
316 }
317
318 if (!$this->checkColumnDefinition($a_def)) {
319 return false;
320 }
321
322 return true;
323 }

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

331 {
332 return $this->field_definition->checkColumnDefinition($a_def);
333 }

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

340 {
341 return $this->field_definition->checkColumnName($a_name);
342 }

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

1769 {
1770 return $this->getFieldDefinition()->checkIndexName($name);
1771 }
getFieldDefinition()

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

297 {
298 foreach ($a_cols as $col => $def) {
299 if (!$this->checkColumn($col, $def)) {
300 return false;
301 }
302 }
303
304 return true;
305 }
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 1574 of file class.ilDBPdo.php.

1574 {
1575 return $this->field_definition->checkTableName($a_name);
1576 }

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

1609 {
1610 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1611 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1612 }
1613
1614 return $this->pdo->commit();
1615 }

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

1450 {
1451 return $this->manager->getQueryUtils()->concat($values, $allow_null);
1452 }

◆ 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.

101 {
102 $this->generateDSN();
103 try {
104 $options = $this->getAttributes();
105 $this->pdo = new PDO($this->getDSN(), $this->getUsername(), $this->getPassword(), $options);
106 $this->initHelpers();
107 $this->initSQLMode();
108 } catch (Exception $e) {
109 $this->error_code = $e->getCode();
110 if ($return_false_for_error) {
111 return false;
112 }
113 throw $e;
114 }
115
116 return ($this->pdo->errorCode() == PDO::ERR_NONE);
117 }
initHelpers()
if(!is_array($argv)) $options

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

924 {
925 return $a_constraint;
926 }

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

171 {
172 $this->setDbname(null);
173 $this->generateDSN();
174 $this->connect(true);
175 try {
176 return $this->query($this->manager->getQueryUtils()->createDatabase($a_name, $a_charset, $a_collation));
177 } catch (PDOException $e) {
178 return false;
179 }
180 }
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 400 of file class.ilDBPdo.php.

400 {
401 $this->manager->createSequence($table_name, $start);
402 }

References $start.

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

274 {
275 // check table name
276 if (!$this->checkTableName($table_name) && !$ignore_erros) {
277 throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
278 }
279
280 // check definition array
281 if (!$this->checkTableColumns($fields) && !$ignore_erros) {
282 throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
283 }
284
285 if ($drop_table) {
286 $this->dropTable($table_name, false);
287 }
288
289 return $this->manager->createTable($table_name, $fields, array());
290 }
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 2072 of file class.ilDBPdo.php.

2073 {
2074 return false;
2075 }

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

880 {
881 $i_name = $this->constraintName($a_table, $a_name) . "_idx";
882 $this->query("ALTER TABLE $a_table DROP FULLTEXT $i_name");
883 }

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

1636 {
1637 return $this->manager->dropIndex($a_table, $a_name);
1638 }

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

374 {
375 foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
376 $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
377 $idx_fields = array_keys((array)$def['fields']);
378
379 if ($idx_fields === $fields) {
380 return $this->dropIndex($table_name, $idx_name);
381 }
382 }
383
384 return false;
385 }
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 1888 of file class.ilDBPdo.php.

1888 {
1889 return $this->manager->dropConstraint($table_name, "PRIMARY", true);
1890 }

◆ dropSequence()

ilDBPdo::dropSequence (   $table_name)
Parameters
$table_namestring

Implements ilDBInterface.

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

544 {
545 $this->manager->dropSequence($table_name);
546 }

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

466 {
467 $ilDBPdoManager = $this->loadModule(ilDBConstants::MODULE_MANAGER);
468 $tables = $ilDBPdoManager->listTables();
469 $table_exists = in_array($table_name, $tables);
470 if (!$table_exists && $error_if_not_existing) {
471 throw new ilDatabaseException("Table {$table_name} does not exist");
472 }
473
474 // drop sequence
475 $sequences = $ilDBPdoManager->listSequences();
476 if (in_array($table_name, $sequences)) {
477 $ilDBPdoManager->dropSequence($table_name);
478 }
479
480 // drop table
481 if ($table_exists) {
482 $ilDBPdoManager->dropTable($table_name);
483 }
484
485 return true;
486 }
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 555 of file class.ilDBPdo.php.

555 {
556 $changes = array(
557 "remove" => array(
558 $column_name => array(),
559 ),
560 );
561
562 return $this->manager->alterTable($table_name, $changes, false);
563 }

◆ dropUniqueConstraint()

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

Implements ilDBPdoInterface.

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

1808 {
1809 return $this->manager->dropConstraint($a_table, $this->constraintName($a_table, $a_name), false);
1810 }

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

1818 {
1819 $analyzer = new ilDBAnalyzer();
1820 $cons = $analyzer->getConstraintsInformation($a_table);
1821 foreach ($cons as $c) {
1822 if ($c["type"] == "unique" && count($a_fields) == count($c["fields"])) {
1823 $all_in = true;
1824 foreach ($a_fields as $f) {
1825 if (!isset($c["fields"][$f])) {
1826 $all_in = false;
1827 }
1828 }
1829 if ($all_in) {
1830 return $this->dropUniqueConstraint($a_table, $c['name']);
1831 }
1832 }
1833 }
1834
1835 return false;
1836 }
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 1333 of file class.ilDBPdo.php.

1333 {
1334 $this->pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $a_status);
1335 }

◆ equals()

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

Implements ilDBInterface.

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

1138 {
1139 if (!$emptyOrNull || $value != "") {
1140 return $columns . " = " . $this->quote($value, $type);
1141 } else {
1142 return "(" . $columns . " = '' OR $columns IS NULL)";
1143 }
1144 }
if(! $in) $columns
Definition: Utf8Test.php:45
quote($value, $type=null)

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

1717 {
1718 return $value;
1719 }

◆ escapePattern()

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

Implements ilDBPdoInterface.

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

1726 {
1727 return $text;
1728 }
$text

References $text.

◆ executeMultiple()

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

Implements ilDBPdoInterface.

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

1897 {
1898 for ($i = 0, $j = count($a_data); $i < $j; $i++) {
1899 $stmt->execute($a_data[$i]);
1900 }
1901 }

◆ fetchAssoc()

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

Implements ilDBInterface.

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

752 {
753 $res = $query_result->fetch(PDO::FETCH_ASSOC);
754 if ($res == null) {
755 $query_result->closeCursor();
756
757 return null;
758 }
759
760 return $res;
761 }

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

627 {
628 $res = $query_result->fetchObject();
629 if ($res == null) {
630 $query_result->closeCursor();
631
632 return null;
633 }
634
635 return $res;
636 }

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

1909 {
1910 return "FROM_UNIXTIME(" . $a_expr . ")";
1911 }

◆ generateDSN()

ilDBPdo::generateDSN ( )

Reimplemented in ilDBPdoPostgreSQL.

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

217 {
218 $port = $this->getPort() ? ";port=" . $this->getPort() : "";
219 $dbname = $this->getDbname() ? ';dbname=' . $this->getDbname() : '';
220 $host = $this->getHost();
221 $charset = ';charset=' . $this->getCharset();
222 $this->dsn = 'mysql:host=' . $host . $port . $dbname . $charset;
223 }

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

143 {
144 return array();
145 }

Referenced by getAttributes().

+ Here is the caller graph for this function:

◆ getAllowedAttributes()

ilDBPdo::getAllowedAttributes ( )

Returns
array

Implements ilDBInterface.

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

1423 {
1424 return $this->field_definition->getAllowedAttributes();
1425 }

◆ getAttributes()

ilDBPdo::getAttributes ( )
protected
Returns
array

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

130 {
132 foreach ($this->getAdditionalAttributes() as $k => $v) {
133 $options[$k] = $v;
134 }
135
136 return $options;
137 }
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 1182 of file class.ilDBPdo.php.

1182 {
1183 return $this->charset;
1184 }

References $charset.

Referenced by generateDSN().

+ Here is the caller graph for this function:

◆ getDbname()

ilDBPdo::getDbname ( )
Returns
string

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

1166 {
1167 return $this->dbname;
1168 }

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

940 {
941 return $this->db_type;
942 }

References $db_type.

◆ getDBVersion()

ilDBPdo::getDBVersion ( )
Returns
string
Exceptions
ilDatabaseException

Implements ilDBPdoInterface.

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

2045 {
2046 $d = $this->fetchObject($this->query("SELECT VERSION() AS version"));
2047
2048 return ($d->version ? $d->version : 'Unknown');
2049 }
for($col=0; $col< 50; $col++) $d
fetchObject($query_result)

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

+ Here is the call graph for this function:

◆ getDSN()

ilDBPdo::getDSN ( )
Returns
string

Implements ilDBInterface.

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

932 {
933 return $this->dsn;
934 }

References $dsn.

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

+ Here is the caller graph for this function:

◆ getFieldDefinition()

ilDBPdo::getFieldDefinition ( )
Returns
ilDBPdoFieldDefinition

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

151 {
153 }

References $field_definition.

Referenced by checkIndexName().

+ Here is the caller graph for this function:

◆ getHost()

ilDBPdo::getHost ( )
Returns
string

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

1150 {
1151 return $this->host;
1152 }

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

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

References ilDBPdoFieldDefinition\INDEX_FORMAT, and sprintf.

◆ getLastErrorCode()

ilDBPdo::getLastErrorCode ( )
Returns
int

Definition at line 186 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 1842 of file class.ilDBPdo.php.

1842 {
1843 return $this->pdo->lastInsertId();
1844 }

◆ getPassword()

ilDBPdo::getPassword ( )
Returns
string

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

1214 {
1215 return $this->password;
1216 }

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

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

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

391 {
392 return "PRIMARY";
393 }

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

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

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

1707 {
1708 return $this->pdo->query('SELECT VERSION()')->fetchColumn();
1709 }

◆ getStorageEngine()

ilDBPdo::getStorageEngine ( )
Returns
string

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

1652 {
1653 return $this->storage_engine;
1654 }

References $storage_engine.

◆ getUsername()

ilDBPdo::getUsername ( )
Returns
string

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

1198 {
1199 return $this->username;
1200 }

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

2081 {
2082 return $this->manager->getQueryUtils()->groupConcat($a_field_name, $a_seperator, $a_order);
2083 }

◆ in()

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

Implements ilDBInterface.

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

1001 {
1002 return $this->manager->getQueryUtils()->in($field, $values, $negate, $type);
1003 }

◆ indexExistsByFields()

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

Implements ilDBInterface.

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

818 {
819 foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
820 $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
821 $idx_fields = array_keys((array)$def['fields']);
822
823 if ($idx_fields === $fields) {
824 return true;
825 }
826 }
827
828 return false;
829 }

◆ initFromIniFile()

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

Implements ilDBInterface.

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

198 {
199 global $ilClientIniFile;
200 if ($tmpClientIniFile instanceof ilIniFile) {
201 $clientIniFile = $tmpClientIniFile;
202 } else {
203 $clientIniFile = $ilClientIniFile;
204 }
205
206 $this->setUsername($clientIniFile->readVariable("db", "user"));
207 $this->setHost($clientIniFile->readVariable("db", "host"));
208 $this->setPort((int)$clientIniFile->readVariable("db", "port"));
209 $this->setPassword($clientIniFile->readVariable("db", "pass"));
210 $this->setDbname($clientIniFile->readVariable("db", "name"));
211 $this->setDBType($clientIniFile->readVariable("db", "type"));
212
213 $this->generateDSN();
214 }
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 123 of file class.ilDBPdo.php.

123 {
124 }

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

605 {
606 $real = array();
607 $fields = array();
608 foreach ($values as $key => $val) {
609 $real[] = $this->quote($val[1], $val[0]);
610 $fields[] = $this->quoteIdentifier($key);
611 }
612 $values = implode(",", $real);
613 $fields = implode(",", $fields);
614 $query = "INSERT INTO " . $table_name . " (" . $fields . ") VALUES (" . $values . ")";
615
617
618 return $this->pdo->exec($query);
619 }
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 889 of file class.ilDBPdo.php.

889 {
890 $set = $this->query("SHOW INDEX FROM " . $a_table);
891 while ($rec = $this->fetchAssoc($set)) {
892 if ($rec["Key_name"] == $a_name && $rec["Index_type"] == "FULLTEXT") {
893 return true;
894 }
895 }
896
897 return false;
898 }
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 1583 of file class.ilDBPdo.php.

1583 {
1584 require_once('./Services/Database/classes/PDO/FieldDefinition/class.ilDBPdoMySQLFieldDefinition.php');
1585 global $DIC;
1586 $ilDBPdoMySQLFieldDefinition = new ilDBPdoMySQLFieldDefinition($DIC['ilDB']);
1587
1588 return $ilDBPdoMySQLFieldDefinition->isReserved($a_word);
1589 }
Class ilDBPdoMySQLFieldDefinition.
global $DIC

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

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

References $column.

◆ listSequences()

ilDBPdo::listSequences ( )
Returns
array

Implements ilDBInterface.

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

1440 {
1441 return $this->manager->listSequences();
1442 }

Referenced by sequenceExists().

+ Here is the caller graph for this function:

◆ listTables()

ilDBPdo::listTables ( )
Returns
array

Implements ilDBInterface.

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

1401 {
1402 return $this->manager->listTables();
1403 }

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

1410 {
1411 switch ($module) {
1413 return $this->manager;
1415 return $this->reverse;
1416 }
1417 }

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

Referenced by dropTable(), 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 1478 of file class.ilDBPdo.php.

1478 {
1479 return $this->manager->getQueryUtils()->locate($a_needle, $a_string, $a_start_pos);
1480 }

◆ lockTables()

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

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

972 {
973 assert(is_array($tables));
974
975 $lock = $this->manager->getQueryUtils()->lock($tables);
976 global $ilLog;
977 if ($ilLog instanceof ilLog) {
978 $ilLog->write('ilDB::lockTables(): ' . $lock);
979 }
980
981 $this->pdo->exec($lock);
982 }
logging
Definition: class.ilLog.php:19

References $ilLog.

◆ lower()

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

Implements ilDBInterface.

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

1288 {
1289 return " LOWER(" . $a_exp . ") ";
1290 }

◆ manipulate()

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

ilDatabaseException

Implements ilDBInterface.

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

727 {
728 global $DIC;
729 $ilBench = $DIC['ilBench'];
730 try {
732 if ($ilBench instanceof ilBenchmark) {
733 $ilBench->startDbBench($query);
734 }
735 $r = $this->pdo->exec($query);
736 if ($ilBench instanceof ilBenchmark) {
737 $ilBench->stopDbBench();
738 }
739 } catch (PDOException $e) {
740 throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query);
741 }
742
743 return $r;
744 }
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 1034 of file class.ilDBPdo.php.

1034 {
1035 if (!is_array($types) || !is_array($values) || count($types) != count($values)) {
1036 throw new ilDatabaseException("ilDB::manipulateF: types and values must be arrays of same size. ($query)");
1037 }
1038 $quoted_values = array();
1039 foreach ($types as $k => $t) {
1040 $quoted_values[] = $this->quote($values[$k], $t);
1041 }
1042 $query = vsprintf($query, $quoted_values);
1043
1044 return $this->manipulate($query);
1045 }
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.

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

1743 {
1744 return array();
1745 }

◆ migrateAllTablesToEngine()

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

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoMySQL.

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

1735 {
1736 return array();
1737 }

◆ modifyTableColumn()

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

ilDatabaseException

Implements ilDBInterface.

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

1490 {
1491 $def = $this->reverse->getTableFieldDefinition($table, $a_column);
1492
1493 $analyzer = new ilDBAnalyzer($this);
1494 $best_alt = $analyzer->getBestDefinitionAlternative($def);
1495 $def = $def[$best_alt];
1496 unset($def["nativetype"]);
1497 unset($def["mdb2type"]);
1498
1499 // check attributes
1500 $ilDBPdoFieldDefinition = $this->field_definition;
1501
1502 $type = ($a_attributes["type"] != "") ? $a_attributes["type"] : $def["type"];
1503 foreach ($def as $k => $v) {
1504 if ($k != "type" && !$ilDBPdoFieldDefinition->isAllowedAttribute($k, $type)) {
1505 unset($def[$k]);
1506 }
1507 }
1508 $check_array = $def;
1509 foreach ($a_attributes as $k => $v) {
1510 $check_array[$k] = $v;
1511 }
1512 if (!$this->checkColumnDefinition($check_array, true)) {
1513 throw new ilDatabaseException("ilDB Error: modifyTableColumn(" . $table . ", " . $a_column . ")");
1514 }
1515
1516 foreach ($a_attributes as $a => $v) {
1517 $def[$a] = $v;
1518 }
1519
1520 $a_attributes["definition"] = $def;
1521
1522 $changes = array(
1523 "change" => array(
1524 $a_column => $a_attributes,
1525 ),
1526 );
1527
1528 return $this->manager->alterTable($table, $changes, false);
1529 }

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

240 {
241 $sequence_table_name = $table_name . '_seq';
242
243 $last_insert_id = $this->pdo->lastInsertId($table_name);
244 if ($last_insert_id) {
245 // return $last_insert_id;
246 }
247
248 if ($this->tableExists($sequence_table_name)) {
249 $stmt = $this->pdo->prepare("SELECT sequence FROM $sequence_table_name");
250 $stmt->execute();
251 $rows = $stmt->fetch(PDO::FETCH_ASSOC);
252 $stmt->closeCursor();
253 $next_id = $rows['sequence'] + 1;
254 $stmt = $this->pdo->prepare("DELETE FROM $sequence_table_name");
255 $stmt->execute(array("next_id" => $next_id));
256 $stmt = $this->pdo->prepare("INSERT INTO $sequence_table_name (sequence) VALUES (:next_id)");
257 $stmt->execute(array("next_id" => $next_id));
258
259 return $next_id;
260 }
261
262 return 1;
263 }
tableExists($table_name)

References tableExists().

+ Here is the call graph for this function:

◆ now()

ilDBPdo::now ( )
Returns
string the now statement

Implements ilDBInterface.

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

1087 {
1088 return $this->manager->getQueryUtils()->now();
1089 }

◆ numRows()

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

Implements ilDBInterface.

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

769 {
770 return $query_result->rowCount();
771 }

◆ prepare()

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

Implements ilDBPdoInterface.

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

1325 {
1326 return new ilPDOStatement($this->pdo->prepare($query));
1327 }
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 1314 of file class.ilDBPdo.php.

1314 {
1315 return new ilPDOStatement($this->pdo->prepare($query));
1316 }

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

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

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

1663 {
1664 switch ($type) {
1666 $type = PDO::FETCH_ASSOC;
1667 break;
1669 $type = PDO::FETCH_OBJ;
1670 break;
1671 default:
1672 $type = PDO::FETCH_ASSOC;
1673 break;
1674 }
1675
1676 return $this->pdo->query($query, PDO::FETCH_ASSOC)->fetchAll(PDO::FETCH_COLUMN, $colnum);
1677 }

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

1013 {
1014 if (!is_array($types) || !is_array($values) || count($types) != count($values)) {
1015 throw new ilDatabaseException("ilDB::queryF: Types and values must be arrays of same size. ($query)");
1016 }
1017 $quoted_values = array();
1018 foreach ($types as $k => $t) {
1019 $quoted_values[] = $this->quote($values[$k], $t);
1020 }
1021 $query = vsprintf($query, $quoted_values);
1022
1023 return $this->query($query);
1024 }

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

1686 {
1687 switch ($fetchmode) {
1689 $type = PDO::FETCH_ASSOC;
1690 break;
1692 $type = PDO::FETCH_OBJ;
1693 break;
1694 default:
1695 $type = PDO::FETCH_ASSOC;
1696 break;
1697 }
1698
1699 return $this->pdo->query($query, $type)->fetch();
1700 }

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

◆ quote()

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

Implements ilDBInterface.

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

780 {
781 if ($value === null) {
782 return 'NULL';
783 }
784
785 $pdo_type = PDO::PARAM_STR;
786 switch ($type) {
790 if ($value === '') {
791 return 'NULL';
792 }
793 break;
795 $value = (int)$value;
796
797 return $value;
798 break;
800 $pdo_type = PDO::PARAM_INT;
801 break;
803 default:
804 $pdo_type = PDO::PARAM_STR;
805 break;
806 }
807
808 return $this->pdo->quote($value, $pdo_type);
809 }

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

230 {
231 return '`' . $identifier . '`';
232 }

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

1550 {
1551 // check table name
1552 try {
1553 $this->checkTableName($a_new_name);
1554 } catch (ilDatabaseException $e) {
1555 throw new ilDatabaseException("ilDB Error: renameTable(" . $a_name . "," . $a_new_name . ")<br />" . $e->getMessage());
1556 }
1557
1558 $this->manager->alterTable($a_name, array("name" => $a_new_name), false);
1559
1560 // The abstraction_progress is no longer used in ILIAS, see http://www.ilias.de/mantis/view.php?id=19513
1561 // $query = "UPDATE abstraction_progress " . "SET table_name = " . $this->quote($a_new_name, 'text') . " " . "WHERE table_name = "
1562 // . $this->quote($a_name, 'text');
1563 // $this->pdo->query($query);
1564
1565 return true;
1566 }

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

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

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

1100 {
1101 $a_columns = array_merge($primaryKeys, $otherColumns);
1102 $fields = array();
1103 $field_values = array();
1104 $placeholders = array();
1105 $types = array();
1106 $values = array();
1107
1108 foreach ($a_columns as $k => $col) {
1109 $fields[] = $k;
1110 $placeholders[] = "%s";
1111 $placeholders2[] = ":$k";
1112 $types[] = $col[0];
1113
1114 // integer auto-typecast (this casts bool values to integer)
1115 if ($col[0] == 'integer' && !is_null($col[1])) {
1116 $col[1] = (int)$col[1];
1117 }
1118
1119 $values[] = $col[1];
1120 $field_values[$k] = $col[1];
1121 }
1122
1123 $q = "REPLACE INTO " . $table . " (" . implode($fields, ",") . ") VALUES (" . implode($placeholders, ",") . ")";
1124
1125 $r = $this->manipulateF($q, $types, $values);
1126
1127 return $r;
1128 }
manipulateF($query, $types, $values)

References $r, and manipulateF().

+ Here is the call graph for this function:

◆ rollback()

ilDBPdo::rollback ( )
Returns
bool
Exceptions

ilDatabaseException

Implements ilDBInterface.

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

1622 {
1623 if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1624 throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1625 }
1626
1627 return $this->pdo->rollBack();
1628 }

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

2056 {
2057 if (!$this->doesCollationSupportMB4Strings()) {
2058 $query_replaced = preg_replace(
2059 '/[\x{10000}-\x{10FFFF}]/u', ilDBConstants::MB4_REPLACEMENT, $query
2060 );
2061 if (!empty($query_replaced)) {
2062 return $query_replaced;
2063 }
2064 }
2065
2066 return $query;
2067 }
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 1432 of file class.ilDBPdo.php.

1432 {
1433 return in_array($sequence, $this->listSequences());
1434 }

References listSequences().

+ Here is the call graph for this function:

◆ setCharset()

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

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

1190 {
1191 $this->charset = $charset;
1192 }

References $charset.

◆ setDBHost()

ilDBPdo::setDBHost (   $host)
Parameters
$host

Implements ilDBInterface.

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

1270 {
1271 $this->setHost($host);
1272 }

References $host, and setHost().

+ Here is the call graph for this function:

◆ setDbname()

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

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

1174 {
1175 $this->dbname = $dbname;
1176 }

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

1262 {
1263 $this->setPassword($password);
1264 }

References $password, and setPassword().

+ Here is the call graph for this function:

◆ setDBPort()

ilDBPdo::setDBPort (   $port)
Parameters
$port

Implements ilDBInterface.

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

1254 {
1255 $this->setPort($port);
1256 }

References $port, and setPort().

+ Here is the call graph for this function:

◆ setDBType()

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

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

949 {
950 $this->db_type = $type;
951 }

Referenced by initFromIniFile().

+ Here is the caller graph for this function:

◆ setDBUser()

ilDBPdo::setDBUser (   $user)
Parameters
$user

Implements ilDBInterface.

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

1246 {
1247 $this->setUsername($user);
1248 }

References setUsername().

+ Here is the call graph for this function:

◆ setFieldDefinition()

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

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

159 {
160 $this->field_definition = $field_definition;
161 }

References $field_definition.

◆ setHost()

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

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

1158 {
1159 $this->host = $host;
1160 }

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

1065 {
1066 $this->limit = $limit;
1067 $this->offset = $offset;
1068 }

References $limit, and $offset.

◆ setPassword()

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

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

1222 {
1223 $this->password = $password;
1224 }

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

1238 {
1239 $this->port = $port;
1240 }

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

1644 {
1645 $this->storage_engine = $storage_engine;
1646 }

References $storage_engine.

◆ setUsername()

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

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

1206 {
1207 $this->username = $username;
1208 }

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

1299 {
1300 $lenstr = "";
1301 if ($a_len > -1) {
1302 $lenstr = ", " . $a_len;
1303 }
1304
1305 return " SUBSTR(" . $a_exp . ", " . $a_pos . $lenstr . ") ";
1306 }

◆ supports()

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

Implements ilDBInterface.

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

1384 {
1385 switch ($feature) {
1387 return $this->supportsTransactions();
1389 return $this->supportsFulltext();
1391 return $this->supportsSlave();
1392 default:
1393 return false;
1394 }
1395 }
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.

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

1751 {
1752 return false;
1753 }

◆ supportsEngineMigration()

ilDBPdo::supportsEngineMigration ( )
Returns
bool

Implements ilDBPdoInterface.

Reimplemented in ilDBPdoMySQL.

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

1759 {
1760 return false;
1761 }

◆ supportsFulltext()

ilDBPdo::supportsFulltext ( )
Returns
bool

Implements ilDBInterface.

Reimplemented in ilDBPdoMySQLInnoDB, ilDBPdoMySQLMyISAM, and ilDBPdoPostgreSQL.

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

1367 {
1368 return false;
1369 }

Referenced by addIndex(), and supports().

+ Here is the caller graph for this function:

◆ supportsSlave()

ilDBPdo::supportsSlave ( )
Returns
bool

Implements ilDBInterface.

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

1359 {
1360 return false;
1361 }

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

1375 {
1376 return false;
1377 }

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

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

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

410 {
411 $result = $this->pdo->prepare("SHOW TABLES LIKE :table_name");
412 $result->execute(array('table_name' => $table_name));
413 $return = $result->rowCount();
414 $result->closeCursor();
415
416 return $return > 0;
417 }

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

1862 {
1863 require_once('./Services/Database/classes/class.ilDBAnalyzer.php');
1864 $analyzer = new ilDBAnalyzer();
1865 $cons = $analyzer->getConstraintsInformation($table);
1866 foreach ($cons as $c) {
1867 if ($c["type"] == "unique" && count($fields) == count($c["fields"])) {
1868 $all_in = true;
1869 foreach ($fields as $f) {
1870 if (!isset($c["fields"][$f])) {
1871 $all_in = false;
1872 }
1873 }
1874 if ($all_in) {
1875 return true;
1876 }
1877 }
1878 }
1879
1880 return false;
1881 }

◆ unixTimestamp()

ilDBPdo::unixTimestamp ( )
Returns
string

Implements ilDBPdoInterface.

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

1917 {
1918 return "UNIX_TIMESTAMP()";
1919 }

◆ unlockTables()

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

ilDatabaseException

Implements ilDBInterface.

Reimplemented in ilDBPdoPostgreSQL.

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

989 {
990 $this->pdo->exec($this->manager->getQueryUtils()->unlock());
991 }

◆ update()

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

Implements ilDBInterface.

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

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

1279 {
1280 return " UPPER(" . $a_exp . ") ";
1281 }

◆ useSlave()

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

TODO

Implements ilDBInterface.

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

1054 {
1055 return false;
1056 }

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: