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)
 
 supportsCollationMigration ()
 
 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 ()
 
 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
 fetchAll ($query_result, $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
 
 substr ($a_exp)
 
 execute ($stmt, $data=array())
 
 free ($a_st)
 

Static Public Member Functions

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

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

Implements ilDBInterface.

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

References constraintName(), and query().

Referenced by addIndex().

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

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

References addFulltextIndex(), array, constraintName(), and supportsFulltext().

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")
Create styles array
The data for the language used.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
+ 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

Implements ilDBInterface.

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

References array, constraintName(), and getPrimaryKeyIdentifier().

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  }
Create styles array
The data for the language used.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
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

Implements ilDBInterface.

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

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

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  }
Class ilDatabaseException.
checkColumnName($a_name)
Create styles array
The data for the language used.
checkColumnDefinition($a_def, $a_modify_mode=false)
+ Here is the call graph for this function:

◆ addUniqueConstraint()

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

Implements ilDBPdoInterface.

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

References $manager, array, checkIndexName(), and constraintName().

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  }
Class ilDatabaseException.
Create styles array
The data for the language used.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
checkIndexName($name)
+ Here is the call graph for this function:

◆ appendLimit()

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

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

References $limit, and $query.

Referenced by query().

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  }
+ 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.

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

1937  {
1938  $fields_values = (array)$fields;
1939  if ($mode == ilDBConstants::MDB2_AUTOQUERY_INSERT) {
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
execute($stmt, $data=array())
autoPrepare($table, $table_fields, $mode=ilDBConstants::MDB2_AUTOQUERY_INSERT, $where=false, $types=null, $result_types=ilDBConstants::MDB2_PREPARE_MANIP)
Create styles array
The data for the language used.
buildManipSQL($table, $table_fields, $mode, $where=false)
$params
Definition: example_049.php:96
+ 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.

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

Referenced by autoExecute().

1972  {
1973  $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
1974 
1975  return $this->prepare($query, $types, $result_types);
1976  }
buildManipSQL($table, $table_fields, $mode, $where=false)
prepare($query, $types=null, $result_types=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ beginTransaction()

ilDBPdo::beginTransaction ( )
Returns
bool
Exceptions

Implements ilDBInterface.

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

References supports().

Referenced by ilDBPdoPostgreSQL\lockTables().

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  }
Class ilDatabaseException.
supports($feature)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildAtomQuery()

ilDBPdo::buildAtomQuery ( )
Returns

Implements ilDBInterface.

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

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

References ilDBConstants\MDB2_AUTOQUERY_DELETE, ilDBConstants\MDB2_AUTOQUERY_INSERT, ilDBConstants\MDB2_AUTOQUERY_SELECT, ilDBConstants\MDB2_AUTOQUERY_UPDATE, and quoteIdentifier().

Referenced by autoExecute(), and autoPrepare().

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  }
Class ilDatabaseException.
quoteIdentifier($identifier, $check_option=false)
+ 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.

References checkColumnDefinition(), and checkColumnName().

Referenced by checkTableColumns().

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  }
checkColumnName($a_name)
checkColumnDefinition($a_def, $a_modify_mode=false)
+ 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.

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

331  {
332  return $this->field_definition->checkColumnDefinition($a_def);
333  }
+ 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.

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

340  {
341  return $this->field_definition->checkColumnName($a_name);
342  }
+ Here is the caller graph for this function:

◆ checkIndexName()

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

Implements ilDBPdoInterface.

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

References getFieldDefinition().

Referenced by addUniqueConstraint().

1769  {
1770  return $this->getFieldDefinition()->checkIndexName($name);
1771  }
getFieldDefinition()
+ 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.

References checkColumn().

Referenced by createTable().

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)
+ 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

Implements ilDBInterface.

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

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

1574  {
1575  return $this->field_definition->checkTableName($a_name);
1576  }
+ Here is the caller graph for this function:

◆ commit()

ilDBPdo::commit ( )
Returns
bool
Exceptions

Implements ilDBInterface.

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

References supports().

Referenced by ilDBPdoPostgreSQL\unlockTables().

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  }
Class ilDatabaseException.
supports($feature)
+ 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

Implements ilDBInterface.

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

References $options, generateDSN(), getAttributes(), getDSN(), getPassword(), getUsername(), initHelpers(), and initSQLMode().

Referenced by createDatabase().

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

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

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

924  {
925  return $a_constraint;
926  }
+ 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
Exceptions

Implements ilDBInterface.

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

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

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  }
query($query)
setDbname($dbname)
connect($return_false_for_error=false)
+ Here is the call graph for this function:

◆ createSequence()

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

Implements ilDBInterface.

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

References $start.

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

◆ 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

Implements ilDBInterface.

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

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

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)
Class ilDatabaseException.
dropTable($table_name, $error_if_not_existing=true)
checkTableColumns($a_cols)
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ doesCollationSupportMB4Strings()

ilDBPdo::doesCollationSupportMB4Strings ( )

Implements ilDBInterface.

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

Referenced by sanitizeMB4StringIfNotSupported().

2073  {
2074  return false;
2075  }
+ 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.

References constraintName(), and query().

880  {
881  $i_name = $this->constraintName($a_table, $a_name) . "_idx";
882  $this->query("ALTER TABLE $a_table DROP FULLTEXT $i_name");
883  }
query($query)
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
+ 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.

Referenced by dropIndexByFields().

1636  {
1637  return $this->manager->dropIndex($a_table, $a_name);
1638  }
+ Here is the caller graph for this function:

◆ dropIndexByFields()

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

Implements ilDBInterface.

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

References array, and dropIndex().

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  }
Create styles array
The data for the language used.
dropIndex($a_table, $a_name="i1")
+ Here is the call graph for this function:

◆ dropPrimaryKey()

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

Implements ilDBPdoInterface.

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

Implements ilDBInterface.

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

References loadModule(), and ilDBConstants\MODULE_MANAGER.

Referenced by createTable().

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  }
Class ilDatabaseException.
loadModule($module)
+ 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

Implements ilDBInterface.

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

References array.

555  {
556  $changes = array(
557  "remove" => array(
558  $column_name => array(),
559  ),
560  );
561 
562  return $this->manager->alterTable($table_name, $changes, false);
563  }
Create styles array
The data for the language used.

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

References constraintName().

Referenced by dropUniqueConstraintByFields().

1808  {
1809  return $this->manager->dropConstraint($a_table, $this->constraintName($a_table, $a_name), false);
1810  }
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
+ 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.

References dropUniqueConstraint().

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  }
dropUniqueConstraint($a_table, $a_name="con")
This class gives all kind of DB information using the MDB2 manager and reverse module.
+ 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.

References $data, $result, array, and ilDBInterface\execute().

1333  {
1334  $this->pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $a_status);
1335  }
+ Here is the call graph for this function:

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

References $columns, and quote().

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

References $text.

1726  {
1727  return $text;
1728  }
$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.

References $res.

Referenced by isFulltextIndex().

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  }
+ 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.

References $res.

Referenced by getDBVersion().

627  {
628  $res = $query_result->fetchObject();
629  if ($res == null) {
630  $query_result->closeCursor();
631 
632  return null;
633  }
634 
635  return $res;
636  }
+ 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 ( )

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

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

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

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  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAdditionalAttributes()

ilDBPdo::getAdditionalAttributes ( )
protected
Returns
array

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

References array.

Referenced by getAttributes().

143  {
144  return array();
145  }
Create styles array
The data for the language used.
+ 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.

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

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

130  {
132  foreach ($this->getAdditionalAttributes() as $k => $v) {
133  $options[$k] = $v;
134  }
135 
136  return $options;
137  }
getAdditionalAttributes()
if(!is_array($argv)) $options
+ 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.

References $charset.

Referenced by generateDSN().

1182  {
1183  return $this->charset;
1184  }
+ Here is the caller graph for this function:

◆ getDbname()

ilDBPdo::getDbname ( )
Returns
string

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

References $dbname.

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

1166  {
1167  return $this->dbname;
1168  }
+ Here is the caller graph for this function:

◆ getDBType()

ilDBPdo::getDBType ( )
Returns
string

Implements ilDBInterface.

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

References $db_type.

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

◆ getDBVersion()

ilDBPdo::getDBVersion ( )
Returns
string
Exceptions
ilDatabaseException

Implements ilDBPdoInterface.

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

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

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
query($query)
fetchObject($query_result)
+ Here is the call graph for this function:

◆ getDSN()

ilDBPdo::getDSN ( )
Returns
string

Implements ilDBInterface.

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

References $dsn.

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

932  {
933  return $this->dsn;
934  }
+ Here is the caller graph for this function:

◆ getFieldDefinition()

ilDBPdo::getFieldDefinition ( )
Returns
ilDBPdoFieldDefinition

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

References $field_definition.

Referenced by checkIndexName().

151  {
153  }
+ Here is the caller graph for this function:

◆ getHost()

ilDBPdo::getHost ( )
Returns
string

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

References $host.

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

1150  {
1151  return $this->host;
1152  }
+ Here is the caller graph for this function:

◆ getIndexName()

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

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

References ilDBPdoFieldDefinition\INDEX_FORMAT.

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

◆ getLastErrorCode()

ilDBPdo::getLastErrorCode ( )
Returns
int

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

References $error_code.

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

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

References $password.

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

1214  {
1215  return $this->password;
1216  }
+ Here is the caller graph for this function:

◆ getPort()

ilDBPdo::getPort ( )
Returns
int

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

References $port.

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

1230  {
1231  return $this->port;
1232  }
+ Here is the caller graph for this function:

◆ getPrimaryKeyIdentifier()

ilDBPdo::getPrimaryKeyIdentifier ( )
Returns
string

Implements ilDBInterface.

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

Referenced by addPrimaryKey().

391  {
392  return "PRIMARY";
393  }
+ 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.

References ilDBPdoFieldDefinition\SEQUENCE_FORMAT.

Referenced by ilDBPdoMySQL\nextId().

914  {
915  return sprintf(ilDBPdoFieldDefinition::SEQUENCE_FORMAT, preg_replace('/[^a-z0-9_\$.]/i', '_', $table_name));
916  }
+ 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.

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

References $storage_engine.

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

◆ getUsername()

ilDBPdo::getUsername ( )
Returns
string

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

References $username.

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

1198  {
1199  return $this->username;
1200  }
+ 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.

References array.

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  }
Create styles array
The data for the language used.

◆ initFromIniFile()

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

Implements ilDBInterface.

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

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

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  }
setPassword($password)
setUsername($username)
setDBType($type)
setHost($host)
setDbname($dbname)
setPort($port)
INIFile Parser.
+ Here is the call graph for this function:

◆ initHelpers()

ilDBPdo::initHelpers ( )
abstract

Referenced by connect().

+ Here is the caller graph for this function:

◆ initSQLMode()

ilDBPdo::initSQLMode ( )
protected

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

Referenced by connect().

123  {
124  }
+ 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.

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

Referenced by ilDBPdoPostgreSQL\replace().

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 to sanitize, all MB4-Characters like emojis will re replaced with ???string sanitized query ...
quote($value, $type=null)
quoteIdentifier($identifier, $check_option=false)
Create styles array
The data for the language used.
+ 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.

References fetchAssoc(), and query().

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  }
query($query)
fetchAssoc($query_result)
+ 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.

References $DIC.

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

◆ like()

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

Implements ilDBInterface.

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

References $column.

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

◆ listSequences()

ilDBPdo::listSequences ( )
Returns
array

Implements ilDBInterface.

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

Referenced by sequenceExists().

1440  {
1441  return $this->manager->listSequences();
1442  }
+ Here is the caller graph for this function:

◆ listTables()

ilDBPdo::listTables ( )
Returns
array

Implements ilDBInterface.

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

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

1401  {
1402  return $this->manager->listTables();
1403  }
+ Here is the caller graph for this function:

◆ loadModule()

ilDBPdo::loadModule (   $module)
Parameters
$module
Returns
|

Implements ilDBInterface.

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

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

Referenced by dropTable(), and tableColumnExists().

1410  {
1411  switch ($module) {
1413  return $this->manager;
1415  return $this->reverse;
1416  }
1417  }
+ 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.

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

References $ilLog.

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:18

◆ 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

Implements ilDBInterface.

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

References $DIC, $ilBench, $query, $r, and sanitizeMB4StringIfNotSupported().

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

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  }
sanitizeMB4StringIfNotSupported($query)
string to sanitize, all MB4-Characters like emojis will re replaced with ???string sanitized query ...
Class ilDatabaseException.
$r
Definition: example_031.php:79
global $ilBench
Definition: ilias.php:18
performance measurement class
global $DIC
+ 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.

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

Referenced by replace(), and update().

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  }
quote($value, $type=null)
Class ilDatabaseException.
Create styles array
The data for the language used.
manipulate($query)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ migrateAllTablesToCollation()

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

Implements ilDBPdoInterface.

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

References array.

1743  {
1744  return array();
1745  }
Create styles array
The data for the language used.

◆ migrateAllTablesToEngine()

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

Implements ilDBPdoInterface.

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

References array.

1735  {
1736  return array();
1737  }
Create styles array
The data for the language used.

◆ modifyTableColumn()

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

Implements ilDBInterface.

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

References $field_definition, array, checkColumnDefinition(), and ilDBInterface\free().

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  }
Class ilDatabaseException.
Create styles array
The data for the language used.
This class gives all kind of DB information using the MDB2 manager and reverse module.
checkColumnDefinition($a_def, $a_modify_mode=false)
+ Here is the call graph for this function:

◆ nextId()

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

Implements ilDBInterface.

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

References array, and tableExists().

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)
Create styles array
The data for the language used.
+ 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

Implements ilDBPdoInterface.

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

References $query.

Referenced by autoPrepare().

1325  {
1326  return new ilPDOStatement($this->pdo->prepare($query));
1327  }
Class ilPDOStatement is a Wrapper Class for PDOStatement.
+ Here is the caller graph for this function:

◆ prepareManip()

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

Implements ilDBInterface.

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

References $query.

Referenced by update().

1314  {
1315  return new ilPDOStatement($this->pdo->prepare($query));
1316  }
Class ilPDOStatement is a Wrapper Class for PDOStatement.
+ 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.

References $data, $ilBench, $info, $query, $res, appendLimit(), array, ilDBInterface\fetchAll(), and ilDBConstants\FETCHMODE_ASSOC.

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

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  }
Class ilPDOStatement is a Wrapper Class for PDOStatement.
Class ilDatabaseException.
$info
Definition: example_052.php:80
appendLimit($query)
global $ilBench
Definition: ilias.php:18
performance measurement class
+ 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.

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

Referenced by ilDBPdoMySQL\migrateAllTablesToEngine().

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  }
+ Here is the caller graph for this function:

◆ queryF()

ilDBPdo::queryF (   $query,
  $types,
  $values 
)
Parameters
string$query

Implements ilDBInterface.

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

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

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  }
quote($value, $type=null)
Class ilDatabaseException.
query($query)
Create styles array
The data for the language used.
+ 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.

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

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  }

◆ quote()

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

Implements ilDBInterface.

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

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().

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  }
+ Here is the caller graph for this function:

◆ quoteIdentifier()

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

Implements ilDBInterface.

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

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

230  {
231  return '`' . $identifier . '`';
232  }
+ 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

Implements ilDBInterface.

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

References array, and checkTableName().

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  }
checkTableName($a_name)
Class ilDatabaseException.
Create styles array
The data for the language used.
+ 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

Implements ilDBInterface.

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

References array, and checkColumnName().

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  }
Class ilDatabaseException.
checkColumnName($a_name)
Create styles array
The data for the language used.
This class gives all kind of DB information using the MDB2 manager and reverse module.
+ 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.

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

References $r, array, and manipulateF().

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)
$r
Definition: example_031.php:79
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ rollback()

ilDBPdo::rollback ( )
Returns
bool
Exceptions

Implements ilDBInterface.

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

References supports().

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  }
Class ilDatabaseException.
supports($feature)
+ 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.

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

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

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()
+ 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.

References listSequences().

1432  {
1433  return in_array($sequence, $this->listSequences());
1434  }
+ Here is the call graph for this function:

◆ setCharset()

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

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

References $charset.

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

◆ setDBHost()

ilDBPdo::setDBHost (   $host)
Parameters
$host

Implements ilDBInterface.

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

References $host, and setHost().

1270  {
1271  $this->setHost($host);
1272  }
setHost($host)
+ Here is the call graph for this function:

◆ setDbname()

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

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

References $dbname.

Referenced by createDatabase(), and initFromIniFile().

1174  {
1175  $this->dbname = $dbname;
1176  }
+ 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.

References $password, and setPassword().

1262  {
1263  $this->setPassword($password);
1264  }
setPassword($password)
+ 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.

References $port, and setPort().

1254  {
1255  $this->setPort($port);
1256  }
setPort($port)
+ Here is the call graph for this function:

◆ setDBType()

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

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

References $ilDB, and ilDBInterface\getReservedWords().

Referenced by initFromIniFile().

949  {
950  $this->db_type = $type;
951  }
+ Here is the call graph for this function:
+ 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.

References setUsername().

1246  {
1247  $this->setUsername($user);
1248  }
setUsername($username)
+ 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.

References $field_definition.

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

◆ setHost()

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

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

References $host.

Referenced by initFromIniFile(), and setDBHost().

1158  {
1159  $this->host = $host;
1160  }
+ 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.

References $limit, and $offset.

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

◆ setPassword()

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

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

References $password.

Referenced by initFromIniFile(), and setDBPassword().

1222  {
1223  $this->password = $password;
1224  }
+ Here is the caller graph for this function:

◆ setPort()

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

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

References $port.

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

1238  {
1239  $this->port = $port;
1240  }
+ Here is the caller graph for this function:

◆ setStorageEngine()

ilDBPdo::setStorageEngine (   $storage_engine)
Parameters
$storage_engine

Implements ilDBInterface.

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

References $storage_engine.

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

◆ setUsername()

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

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

References $username.

Referenced by initFromIniFile(), and setDBUser().

1206  {
1207  $this->username = $username;
1208  }
+ 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.

References supportsFulltext(), supportsSlave(), and supportsTransactions().

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

1384  {
1385  switch ($feature) {
1386  case self::FEATURE_TRANSACTIONS:
1387  return $this->supportsTransactions();
1388  case self::FEATURE_FULLTEXT:
1389  return $this->supportsFulltext();
1390  case self::FEATURE_SLAVE:
1391  return $this->supportsSlave();
1392  default:
1393  return false;
1394  }
1395  }
supportsTransactions()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ supportsCollationMigration()

ilDBPdo::supportsCollationMigration ( )

Implements ilDBPdoInterface.

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

1751  {
1752  return false;
1753  }

◆ supportsEngineMigration()

ilDBPdo::supportsEngineMigration ( )
Returns
bool

Implements ilDBPdoInterface.

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

1759  {
1760  return false;
1761  }

◆ supportsFulltext()

ilDBPdo::supportsFulltext ( )
Returns
bool

Implements ilDBInterface.

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

Referenced by addIndex(), and supports().

1367  {
1368  return false;
1369  }
+ Here is the caller graph for this function:

◆ supportsSlave()

ilDBPdo::supportsSlave ( )
Returns
bool

Implements ilDBInterface.

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

Referenced by supports().

1359  {
1360  return false;
1361  }
+ Here is the caller graph for this function:

◆ supportsTransactions()

ilDBPdo::supportsTransactions ( )
Returns
bool

Implements ilDBInterface.

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

Referenced by supports().

1375  {
1376  return false;
1377  }
+ Here is the caller graph for this function:

◆ tableColumnExists()

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

Implements ilDBInterface.

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

References loadModule(), and ilDBConstants\MODULE_MANAGER.

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  }
loadModule($module)
+ Here is the call graph for this function:

◆ tableExists()

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

Implements ilDBInterface.

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

References $result, and array.

Referenced by nextId().

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  }
$result
Create styles array
The data for the language used.
+ 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  }
This class gives all kind of DB information using the MDB2 manager and reverse module.

◆ 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

Implements ilDBInterface.

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.

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

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  }
sanitizeMB4StringIfNotSupported($query)
string to sanitize, all MB4-Characters like emojis will re replaced with ???string sanitized query ...
execute($stmt, $data=array())
quote($value, $type=null)
manipulateF($query, $types, $values)
$r
Definition: example_031.php:79
quoteIdentifier($identifier, $check_option=false)
Create styles array
The data for the language used.
prepareManip($query, $types=null)
if(! $in) $columns
Definition: Utf8Test.php:45
+ 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:
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.

◆ FEATURE_SLAVE

const ilDBPdo::FEATURE_SLAVE = 'slave'

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

◆ FEATURE_TRANSACTIONS

const ilDBPdo::FEATURE_TRANSACTIONS = 'transactions'

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


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