ILIAS  release_7 Revision v7.30-3-g800a261c036
ilDBPdo Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. 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::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...
 
 primaryExistsByFields (string $table_name, array $fields)
 
Parameters
string$table_name
array$fields
Returns
bool
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::AUTOQUERY_INSERT, $where=false, $types=null, $result_types=ilDBConstants::PREPARE_MANIP)
 
 buildManipSQL ($table, $table_fields, $mode, $where=false)
 

Protected Attributes

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

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class pdoDB

Author
Oskar Truffer ot@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

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

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

References constraintName(), and query().

Referenced by addIndex().

901  {
902  $i_name = $this->constraintName($a_table, $a_name) . "_idx";
903  $f_str = implode(",", $a_fields);
904  $q = "ALTER TABLE $a_table ADD FULLTEXT $i_name ($f_str)";
905  $this->query($q);
906  }
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 868 of file class.ilDBPdo.php.

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

869  {
870  assert(is_array($fields));
871  $this->field_definition->checkIndexName($index_name);
872 
873  $definition_fields = array();
874  foreach ($fields as $f) {
875  $definition_fields[$f] = array();
876  }
877  $definition = array(
878  'fields' => $definition_fields,
879  );
880 
881  if (!$fulltext) {
882  $this->manager->createIndex($table_name, $this->constraintName($table_name, $index_name), $definition);
883  } else {
884  if ($this->supportsFulltext()) {
885  $this->addFulltextIndex($table_name, $fields, $index_name); // TODO
886  }
887  }
888 
889  return true;
890  }
addFulltextIndex($a_table, $a_fields, $a_name="in")
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 356 of file class.ilDBPdo.php.

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

357  {
358  assert(is_array($primary_keys));
359 
360  $fields = array();
361  foreach ($primary_keys as $f) {
362  $fields[$f] = array();
363  }
364  $definition = array(
365  'primary' => true,
366  'fields' => $fields,
367  );
368  $this->manager->createConstraint($table_name, $this->constraintName($table_name, $this->getPrimaryKeyIdentifier()), $definition);
369 
370  return true;
371  }
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 453 of file class.ilDBPdo.php.

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

454  {
455  if (!$this->checkColumnName($column_name)) {
456  throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
457  }
458  if (!$this->checkColumnDefinition($attributes)) {
459  throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
460  }
461 
462  $changes = array(
463  "add" => array(
464  $column_name => $attributes,
465  ),
466  );
467 
468  return $this->manager->alterTable($table_name, $changes, false);
469  }
Class ilDatabaseException.
checkColumnName($a_name)
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 1891 of file class.ilDBPdo.php.

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

1892  {
1893  assert(is_array($fields));
1895 
1896  // check index name
1897  if (!$this->checkIndexName($name)) {
1898  throw new ilDatabaseException("ilDB Error: addUniqueConstraint(" . $table . "," . $name . ")");
1899  }
1900 
1901  $fields_corrected = array();
1902  foreach ($fields as $f) {
1903  $fields_corrected[$f] = array();
1904  }
1905  $definition = array(
1906  'unique' => true,
1907  'fields' => $fields_corrected,
1908  );
1909 
1910  return $manager->createConstraint($table, $this->constraintName($table, $name), $definition);
1911  }
Class ilDatabaseException.
if($format !==null) $name
Definition: metadata.php:230
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 1545 of file class.ilDBPdo.php.

References $limit, and $query.

Referenced by query().

1546  {
1547  if ($this->limit !== null && $this->offset !== null) {
1548  $query .= ' LIMIT ' . (int) $this->offset . ', ' . (int) $this->limit;
1549  $this->limit = null;
1550  $this->offset = null;
1551 
1552  return $query;
1553  }
1554 
1555  return $query;
1556  }
$query
+ Here is the caller graph for this function:

◆ autoExecute()

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

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

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

Implements ilDBPdoInterface.

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

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

2055  {
2056  $fields_values = (array) $fields;
2057  if ($mode == ilDBConstants::AUTOQUERY_INSERT) {
2058  if (!empty($fields_values)) {
2059  $keys = $fields_values;
2060  } else {
2061  $keys = array();
2062  }
2063  } else {
2064  $keys = array_keys($fields_values);
2065  }
2066  $params = array_values($fields_values);
2067  if (empty($params)) {
2068  $query = $this->buildManipSQL($tablename, $keys, $mode, $where);
2069  $result = $this->pdo->query($query);
2070  } else {
2071  $stmt = $this->autoPrepare($tablename, $keys, $mode, $where, $types, $result_types);
2072  $this->execute($stmt);
2073  $this->free($stmt);
2074  $result = $stmt;
2075  }
2076 
2077  return $result;
2078  }
autoPrepare($table, $table_fields, $mode=ilDBConstants::AUTOQUERY_INSERT, $where=false, $types=null, $result_types=ilDBConstants::PREPARE_MANIP)
$result
execute($stmt, $data=array())
$keys
Definition: metadata.php:187
$query
buildManipSQL($table, $table_fields, $mode, $where=false)
+ Here is the call graph for this function:

◆ autoPrepare()

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

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

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

Referenced by autoExecute().

2091  {
2092  $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
2093 
2094  return $this->prepare($query, $types, $result_types);
2095  }
$query
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 1690 of file class.ilDBPdo.php.

References supports().

Referenced by ilDBPdoPostgreSQL\lockTables().

1691  {
1692  if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1693  throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1694  }
1695 
1696  return $this->pdo->beginTransaction();
1697  }
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 1964 of file class.ilDBPdo.php.

1965  {
1966  return new ilAtomQueryLock($this);
1967  }
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 2106 of file class.ilDBPdo.php.

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

Referenced by autoExecute(), and autoPrepare().

2107  {
2108  if ($this->options['quote_identifier']) {
2109  $table = $this->quoteIdentifier($table);
2110  }
2111 
2112  if (!empty($table_fields) && $this->options['quote_identifier']) {
2113  foreach ($table_fields as $key => $field) {
2114  $table_fields[$key] = $this->quoteIdentifier($field);
2115  }
2116  }
2117 
2118  if ($where !== false && !is_null($where)) {
2119  if (is_array($where)) {
2120  $where = implode(' AND ', $where);
2121  }
2122  $where = ' WHERE ' . $where;
2123  }
2124 
2125  switch ($mode) {
2127  if (empty($table_fields)) {
2128  throw new ilDatabaseException('Insert requires table fields');
2129  }
2130  $cols = implode(', ', $table_fields);
2131  $values = '?' . str_repeat(', ?', (count($table_fields) - 1));
2132 
2133  return 'INSERT INTO ' . $table . ' (' . $cols . ') VALUES (' . $values . ')';
2134  break;
2136  if (empty($table_fields)) {
2137  throw new ilDatabaseException('Update requires table fields');
2138  }
2139  $set = implode(' = ?, ', $table_fields) . ' = ?';
2140  $sql = 'UPDATE ' . $table . ' SET ' . $set . $where;
2141 
2142  return $sql;
2143  break;
2145  $sql = 'DELETE FROM ' . $table . $where;
2146 
2147  return $sql;
2148  break;
2150  $cols = !empty($table_fields) ? implode(', ', $table_fields) : '*';
2151  $sql = 'SELECT ' . $cols . ' FROM ' . $table . $where;
2152 
2153  return $sql;
2154  break;
2155  }
2156 
2157  throw new ilDatabaseException('Syntax error');
2158  }
Class ilDatabaseException.
quoteIdentifier($identifier, $check_option=false)
$cols
Definition: xhr_table.php:11
+ 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 2212 of file class.ilDBPdo.php.

2213  {
2214  return $this->manager->getQueryUtils()->cast($a_field_name, $a_dest_type);
2215  }

◆ checkColumn()

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

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

References checkColumnDefinition(), and checkColumnName().

Referenced by checkTableColumns().

316  {
317  if (!$this->checkColumnName($a_col)) {
318  return false;
319  }
320 
321  if (!$this->checkColumnDefinition($a_def)) {
322  return false;
323  }
324 
325  return true;
326  }
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 334 of file class.ilDBPdo.php.

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

335  {
336  return $this->field_definition->checkColumnDefinition($a_def);
337  }
+ Here is the caller graph for this function:

◆ checkColumnName()

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

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

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

345  {
346  return $this->field_definition->checkColumnName($a_name);
347  }
+ Here is the caller graph for this function:

◆ checkIndexName()

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

Implements ilDBPdoInterface.

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

References $name, and getFieldDefinition().

Referenced by addUniqueConstraint().

1879  {
1880  return $this->getFieldDefinition()->checkIndexName($name);
1881  }
if($format !==null) $name
Definition: metadata.php:230
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 298 of file class.ilDBPdo.php.

References checkColumn().

Referenced by createTable().

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

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

1668  {
1669  return $this->field_definition->checkTableName($a_name);
1670  }
+ Here is the caller graph for this function:

◆ commit()

ilDBPdo::commit ( )
Returns
bool
Exceptions

Implements ilDBInterface.

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

References supports().

Referenced by ilDBPdoPostgreSQL\unlockTables().

1705  {
1706  if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1707  throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1708  }
1709 
1710  return $this->pdo->commit();
1711  }
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 1535 of file class.ilDBPdo.php.

1536  {
1537  return $this->manager->getQueryUtils()->concat($values, $allow_null);
1538  }

◆ connect()

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

Implements ilDBInterface.

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

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

Referenced by createDatabase().

108  {
109  $this->generateDSN();
110  try {
111  $options = $this->getAttributes();
112  $this->pdo = new PDO($this->getDSN(), $this->getUsername(), $this->getPassword(), $options);
113  $this->initHelpers();
114  $this->initSQLMode();
115  } catch (Exception $e) {
116  $this->error_code = $e->getCode();
117  if ($return_false_for_error) {
118  return false;
119  }
120  throw $e;
121  }
122 
123  return ($this->pdo->errorCode() == PDO::ERR_NONE);
124  }
initHelpers()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ constraintName()

ilDBPdo::constraintName (   $a_table,
  $a_constraint 
)

Determine contraint name by table name and constraint name.

In MySQL these are "unique" per table

Implements ilDBInterface.

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

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

960  {
961  return $a_constraint;
962  }
+ Here is the caller graph for this function:

◆ createDatabase()

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

Implements ilDBInterface.

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

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

184  {
185  $this->setDbname(null);
186  $this->generateDSN();
187  $this->connect(true);
188  try {
189  return $this->query($this->manager->getQueryUtils()->createDatabase($a_name, $a_charset, $a_collation));
190  } catch (PDOException $e) {
191  return false;
192  }
193  }
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 408 of file class.ilDBPdo.php.

409  {
410  $this->manager->createSequence($table_name, $start);
411  }

◆ 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 checkTableColumns(), checkTableName(), and dropTable().

275  {
276  // check table name
277  if (!$this->checkTableName($table_name) && !$ignore_erros) {
278  throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
279  }
280 
281  // check definition array
282  if (!$this->checkTableColumns($fields) && !$ignore_erros) {
283  throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
284  }
285 
286  if ($drop_table) {
287  $this->dropTable($table_name, false);
288  }
289 
290  return $this->manager->createTable($table_name, $fields, array());
291  }
checkTableName($a_name)
Class ilDatabaseException.
dropTable($table_name, $error_if_not_existing=true)
checkTableColumns($a_cols)
+ Here is the call graph for this function:

◆ doesCollationSupportMB4Strings()

ilDBPdo::doesCollationSupportMB4Strings ( )

Implements ilDBInterface.

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

Referenced by sanitizeMB4StringIfNotSupported().

2196  {
2197  return false;
2198  }
+ Here is the caller graph for this function:

◆ dropFulltextIndex()

ilDBPdo::dropFulltextIndex (   $a_table,
  $a_name 
)

Drop fulltext index.

Implements ilDBInterface.

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

References constraintName(), and query().

913  {
914  $i_name = $this->constraintName($a_table, $a_name) . "_idx";
915  $this->query("ALTER TABLE $a_table DROP FULLTEXT $i_name");
916  }
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 1733 of file class.ilDBPdo.php.

Referenced by dropIndexByFields().

1734  {
1735  return $this->manager->dropIndex($a_table, $a_name);
1736  }
+ 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 380 of file class.ilDBPdo.php.

References dropIndex().

381  {
382  foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
383  $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
384  $idx_fields = array_keys((array) $def['fields']);
385 
386  if ($idx_fields === $fields) {
387  return $this->dropIndex($table_name, $idx_name);
388  }
389  }
390 
391  return false;
392  }
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 2001 of file class.ilDBPdo.php.

2002  {
2003  return $this->manager->dropConstraint($table_name, "PRIMARY", true);
2004  }

◆ dropSequence()

ilDBPdo::dropSequence (   $table_name)
Parameters
$table_namestring

Implements ilDBInterface.

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

561  {
562  $this->manager->dropSequence($table_name);
563  }

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

References loadModule(), and ilDBConstants\MODULE_MANAGER.

Referenced by createTable().

479  {
480  $ilDBPdoManager = $this->loadModule(ilDBConstants::MODULE_MANAGER);
481  $tables = $ilDBPdoManager->listTables();
482  $table_exists = in_array($table_name, $tables);
483  if (!$table_exists && $error_if_not_existing) {
484  throw new ilDatabaseException("Table {$table_name} does not exist");
485  }
486 
487  // drop sequence
488  $sequences = $ilDBPdoManager->listSequences();
489  if (in_array($table_name, $sequences)) {
490  $ilDBPdoManager->dropSequence($table_name);
491  }
492 
493  // drop table
494  if ($table_exists) {
495  $ilDBPdoManager->dropTable($table_name);
496  }
497 
498  return true;
499  }
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 572 of file class.ilDBPdo.php.

573  {
574  $changes = array(
575  "remove" => array(
576  $column_name => array(),
577  ),
578  );
579 
580  return $this->manager->alterTable($table_name, $changes, false);
581  }

◆ dropUniqueConstraint()

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

Implements ilDBPdoInterface.

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

References constraintName().

Referenced by dropUniqueConstraintByFields().

1920  {
1921  return $this->manager->dropConstraint($a_table, $this->constraintName($a_table, $a_name), false);
1922  }
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 1930 of file class.ilDBPdo.php.

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

1931  {
1932  $analyzer = new ilDBAnalyzer();
1933  $cons = $analyzer->getConstraintsInformation($a_table);
1934  foreach ($cons as $c) {
1935  if ($c["type"] == "unique" && count($a_fields) == count($c["fields"])) {
1936  $all_in = true;
1937  foreach ($a_fields as $f) {
1938  if (!isset($c["fields"][$f])) {
1939  $all_in = false;
1940  }
1941  }
1942  if ($all_in) {
1943  return $this->dropUniqueConstraint($a_table, $c['name']);
1944  }
1945  }
1946  }
1947 
1948  return false;
1949  }
$c
Definition: cli.php:37
dropUniqueConstraint($a_table, $a_name="con")
This class gives all kind of DB information using the database 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 1407 of file class.ilDBPdo.php.

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

1408  {
1409  $this->pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $a_status);
1410  }
+ 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 1190 of file class.ilDBPdo.php.

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

1191  {
1192  if (!$emptyOrNull || $value != "") {
1193  return $columns . " = " . $this->quote($value, $type);
1194  } else {
1195  return "(" . $columns . " = '' OR $columns IS NULL)";
1196  }
1197  }
$type
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 1820 of file class.ilDBPdo.php.

1821  {
1822  return $value;
1823  }

◆ escapePattern()

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

Implements ilDBPdoInterface.

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

1831  {
1832  return $text;
1833  }

◆ executeMultiple()

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

Implements ilDBPdoInterface.

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

References $i.

2012  {
2013  for ($i = 0, $j = count($a_data); $i < $j; $i++) {
2014  $stmt->execute($a_data[$i]);
2015  }
2016  }
$i
Definition: metadata.php:24

◆ fetchAssoc()

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

Implements ilDBInterface.

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

References $res.

Referenced by isFulltextIndex().

776  {
777  $res = $query_result->fetch(PDO::FETCH_ASSOC);
778  if ($res == null) {
779  $query_result->closeCursor();
780 
781  return null;
782  }
783 
784  return $res;
785  }
foreach($_POST as $key=> $value) $res
+ Here is the caller graph for this function:

◆ fetchObject()

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

Implements ilDBInterface.

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

References $res.

Referenced by getDBVersion().

648  {
649  $res = $query_result->fetchObject();
650  if ($res == null) {
651  $query_result->closeCursor();
652 
653  return null;
654  }
655 
656  return $res;
657  }
foreach($_POST as $key=> $value) $res
+ 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 2024 of file class.ilDBPdo.php.

2025  {
2026  return "FROM_UNIXTIME(" . $a_expr . ")";
2027  }

◆ generateDSN()

ilDBPdo::generateDSN ( )

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

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

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

239  {
240  $port = $this->getPort() ? ";port=" . $this->getPort() : "";
241  $dbname = $this->getDbname() ? ';dbname=' . $this->getDbname() : '';
242  $host = $this->getHost();
243  $charset = ';charset=' . $this->getCharset();
244  $this->dsn = 'mysql:host=' . $host . $port . $dbname . $charset;
245  }
+ 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 152 of file class.ilDBPdo.php.

Referenced by getAttributes().

153  {
154  return array();
155  }
+ Here is the caller graph for this function:

◆ getAllowedAttributes()

ilDBPdo::getAllowedAttributes ( )

Returns
array

Implements ilDBInterface.

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

1506  {
1507  return $this->field_definition->getAllowedAttributes();
1508  }

◆ getAttributes()

ilDBPdo::getAttributes ( )
protected
Returns
array

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

References $attributes, and getAdditionalAttributes().

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

139  {
140  $options = $this->attributes;
141  foreach ($this->getAdditionalAttributes() as $k => $v) {
142  $options[$k] = $v;
143  }
144 
145  return $options;
146  }
getAdditionalAttributes()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCharset()

ilDBPdo::getCharset ( )
Returns
string

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

References $charset.

Referenced by generateDSN().

1240  {
1241  return $this->charset;
1242  }
+ Here is the caller graph for this function:

◆ getDbname()

ilDBPdo::getDbname ( )
Returns
string

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

References $dbname.

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

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

◆ getDBType()

ilDBPdo::getDBType ( )
Returns
string

Implements ilDBInterface.

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

References $db_type.

978  {
979  return $this->db_type;
980  }

◆ getDBVersion()

ilDBPdo::getDBVersion ( )
Returns
string
Exceptions
ilDatabaseException

Implements ilDBPdoInterface.

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

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

2166  {
2167  $d = $this->fetchObject($this->query("SELECT VERSION() AS version"));
2168 
2169  return ($d->version ? $d->version : 'Unknown');
2170  }
query($query)
fetchObject($query_result)
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
+ Here is the call graph for this function:

◆ getDSN()

ilDBPdo::getDSN ( )
Returns
string

Implements ilDBInterface.

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

References $dsn.

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

969  {
970  return $this->dsn;
971  }
+ Here is the caller graph for this function:

◆ getFieldDefinition()

ilDBPdo::getFieldDefinition ( )
Returns
ilDBPdoFieldDefinition

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

References $field_definition.

Referenced by checkIndexName().

162  {
164  }
+ Here is the caller graph for this function:

◆ getHost()

ilDBPdo::getHost ( )
Returns
string

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

References $host.

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

1204  {
1205  return $this->host;
1206  }
+ Here is the caller graph for this function:

◆ getIndexName()

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

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

References ilDBPdoFieldDefinition\INDEX_FORMAT.

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

◆ getLastErrorCode()

ilDBPdo::getLastErrorCode ( )
Returns
int

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

References $error_code.

200  {
201  if ($this->pdo instanceof PDO) {
202  return $this->pdo->errorCode();
203  }
204 
205  return $this->error_code;
206  }

◆ getLastInsertId()

ilDBPdo::getLastInsertId ( )
Returns
string

Implements ilDBPdoInterface.

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

1956  {
1957  return $this->pdo->lastInsertId();
1958  }

◆ getPassword()

ilDBPdo::getPassword ( )
Returns
string

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

References $password.

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

1276  {
1277  return $this->password;
1278  }
+ Here is the caller graph for this function:

◆ getPort()

ilDBPdo::getPort ( )
Returns
int

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

References $port.

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

1294  {
1295  return $this->port;
1296  }
+ Here is the caller graph for this function:

◆ getPrimaryKeyIdentifier()

ilDBPdo::getPrimaryKeyIdentifier ( )
Returns
string

Implements ilDBInterface.

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

Referenced by addPrimaryKey().

399  {
400  return "PRIMARY";
401  }
+ Here is the caller graph for this function:

◆ getSequenceName()

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

Implements ilDBInterface.

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

References ilDBPdoFieldDefinition\SEQUENCE_FORMAT.

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

950  {
951  return sprintf(ilDBPdoFieldDefinition::SEQUENCE_FORMAT, preg_replace('/[^a-z0-9_\$.]/i', '_', $table_name));
952  }
+ Here is the caller graph for this function:

◆ getServerVersion()

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

Implements ilDBPdoInterface.

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

1810  {
1811  return $this->pdo->query('SELECT VERSION()')->fetchColumn();
1812  }

◆ getStorageEngine()

ilDBPdo::getStorageEngine ( )
Returns
string

Implements ilDBInterface.

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

References $storage_engine.

1752  {
1753  return $this->storage_engine;
1754  }

◆ getUsername()

ilDBPdo::getUsername ( )
Returns
string

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

References $username.

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

1258  {
1259  return $this->username;
1260  }
+ 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 2204 of file class.ilDBPdo.php.

2205  {
2206  return $this->manager->getQueryUtils()->groupConcat($a_field_name, $a_seperator, $a_order);
2207  }

◆ in()

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

Implements ilDBInterface.

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

References $type.

1046  {
1047  return $this->manager->getQueryUtils()->in($field, $values, $negate, $type);
1048  }
$type

◆ indexExistsByFields()

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

Implements ilDBInterface.

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

848  {
849  foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
850  $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
851  $idx_fields = array_keys((array) $def['fields']);
852 
853  if ($idx_fields === $fields) {
854  return true;
855  }
856  }
857 
858  return false;
859  }

◆ initFromIniFile()

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

Implements ilDBInterface.

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

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

213  {
214  global $DIC;
215 
216  if ($tmpClientIniFile instanceof ilIniFile) {
217  $clientIniFile = $tmpClientIniFile;
218  } else {
219  $ilClientIniFile = null;
220  if ($DIC->offsetExists('ilClientIniFile')) {
221  $clientIniFile = $DIC['ilClientIniFile'];
222  } else {
223  throw new InvalidArgumentException('$tmpClientIniFile is not an instance of ilIniFile');
224  }
225  }
226 
227  $this->setUsername($clientIniFile->readVariable("db", "user"));
228  $this->setHost($clientIniFile->readVariable("db", "host"));
229  $this->setPort((int) $clientIniFile->readVariable("db", "port"));
230  $this->setPassword($clientIniFile->readVariable("db", "pass"));
231  $this->setDbname($clientIniFile->readVariable("db", "name"));
232  $this->setDBType($clientIniFile->readVariable("db", "type"));
233 
234  $this->generateDSN();
235  }
setPassword($password)
setUsername($username)
setDBType($type)
setHost($host)
global $DIC
Definition: goto.php:24
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 130 of file class.ilDBPdo.php.

Referenced by connect().

131  {
132  }
+ 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 624 of file class.ilDBPdo.php.

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

Referenced by ilDBPdoPostgreSQL\replace().

625  {
626  $real = array();
627  $fields = array();
628  foreach ($values as $key => $val) {
629  $real[] = $this->quote($val[1], $val[0]);
630  $fields[] = $this->quoteIdentifier($key);
631  }
632  $values = implode(",", $real);
633  $fields = implode(",", $fields);
634  $query = "INSERT INTO " . $this->quoteIdentifier($table_name) . " (" . $fields . ") VALUES (" . $values . ")";
635 
637 
638  return $this->pdo->exec($query);
639  }
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)
$query
+ 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 922 of file class.ilDBPdo.php.

References fetchAssoc(), and query().

923  {
924  $set = $this->query("SHOW INDEX FROM " . $a_table);
925  while ($rec = $this->fetchAssoc($set)) {
926  if ($rec["Key_name"] == $a_name && $rec["Index_type"] == "FULLTEXT") {
927  return true;
928  }
929  }
930 
931  return false;
932  }
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 1677 of file class.ilDBPdo.php.

References $DIC, and ilDBPdoFieldDefinition\isReserved().

1678  {
1679  global $DIC;
1680  $ilDBPdoMySQLFieldDefinition = new ilDBPdoMySQLFieldDefinition($DIC->database());
1681 
1682  return $ilDBPdoMySQLFieldDefinition->isReserved($a_word);
1683  }
global $DIC
Definition: goto.php:24
Class ilDBPdoMySQLFieldDefinition.
+ Here is the call graph for this function:

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

References $type.

1129  {
1130  return $this->manager->getQueryUtils()->like($column, $type, $value, $case_insensitive);
1131  }
$type

◆ listSequences()

ilDBPdo::listSequences ( )
Returns
array

Implements ilDBInterface.

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

Referenced by sequenceExists().

1525  {
1526  return $this->manager->listSequences();
1527  }
+ Here is the caller graph for this function:

◆ listTables()

ilDBPdo::listTables ( )
Returns
array

Implements ilDBInterface.

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

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

1482  {
1483  return $this->manager->listTables();
1484  }
+ Here is the caller graph for this function:

◆ loadModule()

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

Implements ilDBInterface.

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

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

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

1492  {
1493  switch ($module) {
1495  return $this->manager;
1497  return $this->reverse;
1498  }
1499  }
+ 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 1565 of file class.ilDBPdo.php.

1566  {
1567  return $this->manager->getQueryUtils()->locate($a_needle, $a_string, $a_start_pos);
1568  }

◆ lockTables()

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

Implements ilDBInterface.

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

References $DIC.

1014  {
1015  assert(is_array($tables));
1016 
1017  $lock = $this->manager->getQueryUtils()->lock($tables);
1018  global $DIC;
1019  $ilLogger = $DIC->logger()->root();
1020  if ($ilLogger instanceof ilLogger) {
1021  $ilLogger->log('ilDB::lockTables(): ' . $lock);
1022  }
1023 
1024  $this->pdo->exec($lock);
1025  }
global $DIC
Definition: goto.php:24
Component logger with individual log levels by component id.

◆ lower()

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

Implements ilDBInterface.

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

1359  {
1360  return " LOWER(" . $a_exp . ") ";
1361  }

◆ manipulate()

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

Implements ilDBInterface.

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

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

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

750  {
751  global $DIC;
752  $ilBench = $DIC['ilBench'] ?? null;
753  try {
755  if ($ilBench instanceof ilBenchmark) {
756  $ilBench->startDbBench($query);
757  }
758  $r = $this->pdo->exec($query);
759  if ($ilBench instanceof ilBenchmark) {
760  $ilBench->stopDbBench();
761  }
762  } catch (PDOException $e) {
763  throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query);
764  }
765 
766  return $r;
767  }
sanitizeMB4StringIfNotSupported($query)
string to sanitize, all MB4-Characters like emojis will re replaced with ???string sanitized query ...
Class ilDatabaseException.
global $DIC
Definition: goto.php:24
$query
global $ilBench
Definition: ilias.php:21
performance measurement class
+ 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 1080 of file class.ilDBPdo.php.

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

Referenced by replace(), and update().

1081  {
1082  if (!is_array($types) || !is_array($values) || count($types) != count($values)) {
1083  throw new ilDatabaseException("ilDB::manipulateF: types and values must be arrays of same size. ($query)");
1084  }
1085  $quoted_values = array();
1086  foreach ($types as $k => $t) {
1087  $quoted_values[] = $this->quote($values[$k], $t);
1088  }
1089  $query = vsprintf($query, $quoted_values);
1090 
1091  return $this->manipulate($query);
1092  }
quote($value, $type=null)
Class ilDatabaseException.
$query
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 1849 of file class.ilDBPdo.php.

1850  {
1851  return array();
1852  }

◆ migrateAllTablesToEngine()

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

Implements ilDBPdoInterface.

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

1841  {
1842  return array();
1843  }

◆ modifyTableColumn()

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

Implements ilDBInterface.

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

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

1579  {
1580  $def = $this->reverse->getTableFieldDefinition($table, $a_column);
1581 
1582  $analyzer = new ilDBAnalyzer($this);
1583  $best_alt = $analyzer->getBestDefinitionAlternative($def);
1584  $def = $def[$best_alt];
1585  unset($def["nativetype"]);
1586  unset($def["mdb2type"]);
1587 
1588  // check attributes
1589  $ilDBPdoFieldDefinition = $this->field_definition;
1590 
1591  $type = ($a_attributes["type"] ?? "" != "") ? $a_attributes["type"] : $def["type"];
1592  foreach ($def as $k => $v) {
1593  if ($k != "type" && !$ilDBPdoFieldDefinition->isAllowedAttribute($k, $type)) {
1594  unset($def[$k]);
1595  }
1596  }
1597  $check_array = $def;
1598  foreach ($a_attributes as $k => $v) {
1599  $check_array[$k] = $v;
1600  }
1601  if (!$this->checkColumnDefinition($check_array, true)) {
1602  throw new ilDatabaseException("ilDB Error: modifyTableColumn(" . $table . ", " . $a_column . ")");
1603  }
1604 
1605  foreach ($a_attributes as $a => $v) {
1606  $def[$a] = $v;
1607  }
1608 
1609  $a_attributes["definition"] = $def;
1610 
1611  $changes = array(
1612  "change" => array(
1613  $a_column => $a_attributes,
1614  ),
1615  );
1616 
1617  return $this->manager->alterTable($table, $changes, false);
1618  }
$type
Class ilDatabaseException.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
This class gives all kind of DB information using the database manager and reverse module...
checkColumnDefinition($a_def, $a_modify_mode=false)
+ Here is the call graph for this function:

◆ nextId()

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

Implements ilDBInterface.

Referenced by quoteIdentifier().

+ Here is the caller graph for this function:

◆ now()

ilDBPdo::now ( )
Returns
string the now statement

Implements ilDBInterface.

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

Referenced by quote().

1138  {
1139  return $this->manager->getQueryUtils()->now();
1140  }
+ Here is the caller graph for this function:

◆ numRows()

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

Implements ilDBInterface.

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

794  {
795  return $query_result->rowCount();
796  }

◆ prepare()

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

Implements ilDBInterface.

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

References $query.

Referenced by autoPrepare().

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

◆ prepareManip()

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

Implements ilDBInterface.

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

References $query.

Referenced by update().

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

◆ primaryExistsByFields()

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

Parameters
string$table_name
array$fields
Returns
bool

Implements ilDBInterface.

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

2220  : bool
2221  {
2222  $constraints = $this->manager->listTableConstraints($table_name);
2223 
2224  if (in_array('primary', $constraints)) {
2225  $definitions = $this->reverse->getTableConstraintDefinition($table_name, 'primary');
2226  $primary_fields = array_keys($definitions['fields']);
2227  sort($primary_fields);
2228  sort($fields);
2229 
2230  return $primary_fields === $fields;
2231  }
2232  return false;
2233  }

◆ query()

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

Implements ilDBInterface.

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

References $data, $DIC, Vendor\Package\$e, $ilBench, $query, $res, appendLimit(), ilDBInterface\fetchAll(), and ilDBConstants\FETCHMODE_ASSOC.

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

509  {
510  global $DIC;
511  $ilBench = $DIC['ilBench'] ?? null;
512 
513  $query = $this->appendLimit($query);
514 
515  try {
516  if ($ilBench instanceof ilBenchmark) {
517  $ilBench->startDbBench($query);
518  }
519  $res = $this->pdo->query($query);
520  if ($ilBench instanceof ilBenchmark) {
521  $ilBench->stopDbBench();
522  }
523  } catch (PDOException $e) {
524  throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query);
525  }
526 
527  $err = $this->pdo->errorCode();
528  if ($err != PDO::ERR_NONE) {
529  $info = $this->pdo->errorInfo();
530  $info_message = $info[2];
531  throw new ilDatabaseException($info_message . ' QUERY: ' . $query);
532  }
533 
534  return new ilPDOStatement($res);
535  }
Class ilPDOStatement is a Wrapper Class for PDOStatement.
Class ilDatabaseException.
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
$query
appendLimit($query)
global $ilBench
Definition: ilias.php:21
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 1763 of file class.ilDBPdo.php.

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

Referenced by ilDBPdoMySQL\migrateAllTablesToEngine().

1764  {
1765  switch ($type) {
1767  $type = PDO::FETCH_ASSOC;
1768  break;
1770  $type = PDO::FETCH_OBJ;
1771  break;
1772  default:
1773  $type = PDO::FETCH_ASSOC;
1774  break;
1775  }
1776 
1777  return $this->pdo->query($query, PDO::FETCH_ASSOC)->fetchAll(PDO::FETCH_COLUMN, $colnum);
1778  }
$type
$query
+ Here is the caller graph for this function:

◆ queryF()

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

Implements ilDBInterface.

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

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

1059  {
1060  if (!is_array($types) || !is_array($values) || count($types) != count($values)) {
1061  throw new ilDatabaseException("ilDB::queryF: Types and values must be arrays of same size. ($query)");
1062  }
1063  $quoted_values = array();
1064  foreach ($types as $k => $t) {
1065  $quoted_values[] = $this->quote($values[$k], $t);
1066  }
1067  $query = vsprintf($query, $quoted_values);
1068 
1069  return $this->query($query);
1070  }
quote($value, $type=null)
Class ilDatabaseException.
query($query)
$query
+ 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 1787 of file class.ilDBPdo.php.

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

1788  {
1789  switch ($fetchmode) {
1791  $type = PDO::FETCH_ASSOC;
1792  break;
1794  $type = PDO::FETCH_OBJ;
1795  break;
1796  default:
1797  $type = PDO::FETCH_ASSOC;
1798  break;
1799  }
1800 
1801  return $this->pdo->query($query, $type)->fetch();
1802  }
$type
$query

◆ quote()

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

Implements ilDBInterface.

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

References $type, now(), 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().

806  {
807  if ($value === null) {
808  return 'NULL';
809  }
810 
811  $pdo_type = PDO::PARAM_STR;
812  switch ($type) {
816  if ($value === '') {
817  return 'NULL';
818  }
819  if ($value === $this->now()) {
820  return $value;
821  }
822  break;
824  $value = (int) $value;
825 
826  return $value;
827  break;
829  $pdo_type = PDO::PARAM_INT;
830  break;
832  default:
833  $pdo_type = PDO::PARAM_STR;
834  break;
835  }
836 
837  return $this->pdo->quote($value, $pdo_type);
838  }
$type
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quoteIdentifier()

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

Implements ilDBInterface.

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

References nextId().

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

253  {
254  return '`' . $identifier . '`';
255  }
+ Here is the call graph for this function:
+ 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 1640 of file class.ilDBPdo.php.

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

1641  {
1642  // check table name
1643  try {
1644  $this->checkTableName($a_new_name);
1645  } catch (ilDatabaseException $e) {
1646  throw new ilDatabaseException("ilDB Error: renameTable(" . $a_name . "," . $a_new_name . ")<br />" . $e->getMessage());
1647  }
1648 
1649  $this->manager->alterTable($a_name, ["name" => $a_new_name], false);
1650  if ($this->sequenceExists($a_name)) {
1651  $this->manager->alterTable($this->getSequenceName($a_name), ["name" => $this->getSequenceName($a_new_name)], false);
1652  }
1653  // The abstraction_progress is no longer used in ILIAS, see http://www.ilias.de/mantis/view.php?id=19513
1654  // $query = "UPDATE abstraction_progress " . "SET table_name = " . $this->quote($a_new_name, 'text') . " " . "WHERE table_name = "
1655  // . $this->quote($a_name, 'text');
1656  // $this->pdo->query($query);
1657 
1658  return true;
1659  }
checkTableName($a_name)
getSequenceName($table_name)
sequenceExists($sequence)
Class ilDatabaseException.
+ 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 591 of file class.ilDBPdo.php.

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

592  {
593  // check table name
594  if (!$this->checkColumnName($column_new_name)) {
595  throw new ilDatabaseException("ilDB Error: renameTableColumn(" . $table_name . "," . $column_old_name . "," . $column_new_name . ")");
596  }
597 
598  $def = $this->reverse->getTableFieldDefinition($table_name, $column_old_name);
599 
600  $analyzer = new ilDBAnalyzer($this);
601  $best_alt = $analyzer->getBestDefinitionAlternative($def);
602  $def = $def[$best_alt];
603  unset($def["nativetype"]);
604  unset($def["mdb2type"]);
605 
606  $f["definition"] = $def;
607  $f["name"] = $column_new_name;
608 
609  $changes = array(
610  "rename" => array(
611  $column_old_name => $f,
612  ),
613  );
614 
615  return $this->manager->alterTable($table_name, $changes, false);
616  }
Class ilDatabaseException.
checkColumnName($a_name)
This class gives all kind of DB information using the database 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 1151 of file class.ilDBPdo.php.

References manipulateF(), and quoteIdentifier().

1152  {
1153  $a_columns = array_merge($primaryKeys, $otherColumns);
1154  $fields = array();
1155  $field_values = array();
1156  $placeholders = array();
1157  $types = array();
1158  $values = array();
1159 
1160  foreach ($a_columns as $k => $col) {
1161  $fields[] = $this->quoteIdentifier($k);
1162  $placeholders[] = "%s";
1163  $placeholders2[] = ":$k";
1164  $types[] = $col[0];
1165 
1166  // integer auto-typecast (this casts bool values to integer)
1167  if ($col[0] == 'integer' && !is_null($col[1])) {
1168  $col[1] = (int) $col[1];
1169  }
1170 
1171  $values[] = $col[1];
1172  $field_values[$k] = $col[1];
1173  }
1174 
1175  $q = "REPLACE INTO " . $table . " (" . implode(",", $fields) . ") VALUES (" . implode(",", $placeholders) . ")";
1176 
1177  $r = $this->manipulateF($q, $types, $values);
1178 
1179  return $r;
1180  }
manipulateF($query, $types, $values)
quoteIdentifier($identifier, $check_option=false)
+ Here is the call graph for this function:

◆ rollback()

ilDBPdo::rollback ( )
Returns
bool
Exceptions

Implements ilDBInterface.

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

References supports().

1719  {
1720  if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1721  throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1722  }
1723 
1724  return $this->pdo->rollBack();
1725  }
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 2176 of file class.ilDBPdo.php.

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

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

2177  {
2178  if (!$this->doesCollationSupportMB4Strings()) {
2179  $query_replaced = preg_replace(
2180  '/[\x{10000}-\x{10FFFF}]/u',
2182  $query
2183  );
2184  if (!empty($query_replaced)) {
2185  return $query_replaced;
2186  }
2187  }
2188 
2189  return $query;
2190  }
doesCollationSupportMB4Strings()
$query
+ 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 1515 of file class.ilDBPdo.php.

References listSequences().

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

1516  {
1517  return in_array($sequence, $this->listSequences());
1518  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCharset()

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

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

References $charset.

1249  {
1250  $this->charset = $charset;
1251  }

◆ setDBHost()

ilDBPdo::setDBHost (   $host)
Parameters
$host

Implements ilDBInterface.

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

References $host, and setHost().

1339  {
1340  $this->setHost($host);
1341  }
setHost($host)
+ Here is the call graph for this function:

◆ setDbname()

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

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

References $dbname.

Referenced by createDatabase(), and initFromIniFile().

1231  {
1232  $this->dbname = $dbname;
1233  }
+ Here is the caller graph for this function:

◆ setDBPassword()

ilDBPdo::setDBPassword (   $password)
Parameters
$password

Implements ilDBInterface.

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

References $password, and setPassword().

1330  {
1331  $this->setPassword($password);
1332  }
setPassword($password)
+ Here is the call graph for this function:

◆ setDBPort()

ilDBPdo::setDBPort (   $port)
Parameters
$port

Implements ilDBInterface.

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

References $port, and setPort().

1321  {
1322  $this->setPort($port);
1323  }
setPort($port)
+ Here is the call graph for this function:

◆ setDBType()

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

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

References $DIC, $ilDB, $type, and ilDBInterface\getReservedWords().

Referenced by initFromIniFile().

988  {
989  $this->db_type = $type;
990  }
$type
+ 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 1311 of file class.ilDBPdo.php.

References setUsername().

1312  {
1313  $this->setUsername($user);
1314  }
setUsername($username)
+ Here is the call graph for this function:

◆ setFieldDefinition()

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

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

References $field_definition.

171  {
172  $this->field_definition = $field_definition;
173  }

◆ setHost()

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

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

References $host.

Referenced by initFromIniFile(), and setDBHost().

1213  {
1214  $this->host = $host;
1215  }
+ 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 1113 of file class.ilDBPdo.php.

References $limit, and $offset.

1114  {
1115  $this->limit = $limit;
1116  $this->offset = $offset;
1117  }

◆ setPassword()

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

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

References $password.

Referenced by initFromIniFile(), and setDBPassword().

1285  {
1286  $this->password = $password;
1287  }
+ Here is the caller graph for this function:

◆ setPort()

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

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

References $port.

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

1303  {
1304  $this->port = $port;
1305  }
+ Here is the caller graph for this function:

◆ setStorageEngine()

ilDBPdo::setStorageEngine (   $storage_engine)
Parameters
$storage_engine

Implements ilDBInterface.

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

References $storage_engine.

1743  {
1744  $this->storage_engine = $storage_engine;
1745  }

◆ setUsername()

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

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

References $username.

Referenced by initFromIniFile(), and setDBUser().

1267  {
1268  $this->username = $username;
1269  }
+ 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 1370 of file class.ilDBPdo.php.

1371  {
1372  $lenstr = "";
1373  if ($a_len > -1) {
1374  $lenstr = ", " . $a_len;
1375  }
1376 
1377  return " SUBSTR(" . $a_exp . ", " . $a_pos . $lenstr . ") ";
1378  }

◆ supports()

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

Implements ilDBInterface.

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

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

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

1464  {
1465  switch ($feature) {
1466  case self::FEATURE_TRANSACTIONS:
1467  return $this->supportsTransactions();
1468  case self::FEATURE_FULLTEXT:
1469  return $this->supportsFulltext();
1470  case self::FEATURE_SLAVE:
1471  return $this->supportsSlave();
1472  default:
1473  return false;
1474  }
1475  }
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 1858 of file class.ilDBPdo.php.

1859  {
1860  return false;
1861  }

◆ supportsEngineMigration()

ilDBPdo::supportsEngineMigration ( )
Returns
bool

Implements ilDBPdoInterface.

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

1868  {
1869  return false;
1870  }

◆ supportsFulltext()

ilDBPdo::supportsFulltext ( )
Returns
bool

Implements ilDBInterface.

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

Referenced by addIndex(), and supports().

1445  {
1446  return false;
1447  }
+ Here is the caller graph for this function:

◆ supportsSlave()

ilDBPdo::supportsSlave ( )
Returns
bool

Implements ilDBInterface.

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

Referenced by supports().

1436  {
1437  return false;
1438  }
+ Here is the caller graph for this function:

◆ supportsTransactions()

ilDBPdo::supportsTransactions ( )
Returns
bool

Implements ilDBInterface.

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

Referenced by supports().

1454  {
1455  return false;
1456  }
+ 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 436 of file class.ilDBPdo.php.

References loadModule(), and ilDBConstants\MODULE_MANAGER.

437  {
438  $fields = $this->loadModule(ilDBConstants::MODULE_MANAGER)->listTableFields($table_name);
439 
440  $in_array = in_array($column_name, $fields);
441 
442  return $in_array;
443  }
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 419 of file class.ilDBPdo.php.

References $result.

420  {
421  $result = $this->pdo->prepare("SHOW TABLES LIKE :table_name");
422  $result->execute(array('table_name' => $table_name));
423  $return = $result->rowCount();
424  $result->closeCursor();
425 
426  return $return > 0;
427  }
$result

◆ uniqueConstraintExists()

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

Implements ilDBPdoInterface.

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

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

1976  {
1977  $analyzer = new ilDBAnalyzer();
1978  $cons = $analyzer->getConstraintsInformation($table);
1979  foreach ($cons as $c) {
1980  if ($c["type"] == "unique" && count($fields) == count($c["fields"])) {
1981  $all_in = true;
1982  foreach ($fields as $f) {
1983  if (!isset($c["fields"][$f])) {
1984  $all_in = false;
1985  }
1986  }
1987  if ($all_in) {
1988  return true;
1989  }
1990  }
1991  }
1992 
1993  return false;
1994  }
$c
Definition: cli.php:37
This class gives all kind of DB information using the database manager and reverse module...

◆ unixTimestamp()

ilDBPdo::unixTimestamp ( )
Returns
string

Implements ilDBPdoInterface.

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

2034  {
2035  return "UNIX_TIMESTAMP()";
2036  }

◆ unlockTables()

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

Implements ilDBInterface.

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

1033  {
1034  $this->pdo->exec($this->manager->getQueryUtils()->unlock());
1035  }

◆ update()

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

Implements ilDBInterface.

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

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

667  {
668  $fields = array();
669  $field_values = array();
670  $placeholders = array();
671  $placeholders_full = array();
672  $types = array();
673  $values = array();
674  $lobs = false;
675  $lob = array();
676  foreach ($columns as $k => $col) {
677  $field_value = $col[1];
678  $fields[] = $k;
679  $placeholders[] = "%s";
680  $placeholders_full[] = ":$k";
681  $types[] = $col[0];
682 
683  if ($col[0] == "blob" || $col[0] == "clob" || $col[0] == 'text') {
684  $field_value = $this->sanitizeMB4StringIfNotSupported($field_value);
685  }
686 
687  // integer auto-typecast (this casts bool values to integer)
688  if ($col[0] == 'integer' && !is_null($field_value)) {
689  $field_value = (int) $field_value;
690  }
691 
692  $values[] = $field_value;
693  $field_values[$k] = $field_value;
694  if ($col[0] == "blob" || $col[0] == "clob") {
695  $lobs = true;
696  $lob[$k] = $k;
697  }
698  }
699 
700  if ($lobs) {
701  $q = "UPDATE " . $this->quoteIdentifier($table_name) . " SET ";
702  $lim = "";
703  foreach ($fields as $k => $field) {
704  $q .= $lim . $this->quoteIdentifier($field) . " = " . $placeholders_full[$k];
705  $lim = ", ";
706  }
707  $q .= " WHERE ";
708  $lim = "";
709  foreach ($where as $k => $col) {
710  $q .= $lim . $this->quoteIdentifier($k) . " = " . $this->quote($col[1], $col[0]);
711  $lim = " AND ";
712  }
713 
714  $r = $this->prepareManip($q, $types);
715  $this->execute($r, $field_values);
716  $this->free($r);
717  } else {
718  foreach ($where as $k => $col) {
719  $types[] = $col[0];
720  $values[] = $col[1];
721  $field_values[$k] = $col;
722  }
723  $q = "UPDATE " . $this->quoteIdentifier($table_name) . " SET ";
724  $lim = "";
725  foreach ($fields as $k => $field) {
726  $q .= $lim . $this->quoteIdentifier($field) . " = " . $placeholders[$k];
727  $lim = ", ";
728  }
729  $q .= " WHERE ";
730  $lim = "";
731  foreach ($where as $k => $col) {
732  $q .= $lim . $this->quoteIdentifier($k) . " = %s";
733  $lim = " AND ";
734  }
735 
736  $r = $this->manipulateF($q, $types, $values);
737  }
738 
739  return $r;
740  }
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)
quoteIdentifier($identifier, $check_option=false)
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 1348 of file class.ilDBPdo.php.

1349  {
1350  return " UPPER(" . $a_exp . ") ";
1351  }

◆ useSlave()

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

TODO

Implements ilDBInterface.

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

1102  {
1103  return false;
1104  }

Field Documentation

◆ $attributes

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

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

Referenced by addTableColumn(), and getAttributes().

◆ $charset

ilDBPdo::$charset = 'utf8'
protected

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

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

◆ $db_type

ilDBPdo::$db_type = ''
protected

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

Referenced by getDBType().

◆ $dbname

ilDBPdo::$dbname = ''
protected

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

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

◆ $dsn

ilDBPdo::$dsn = ''
protected

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

Referenced by getDSN().

◆ $error_code

ilDBPdo::$error_code = 0
protected

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

Referenced by getLastErrorCode().

◆ $field_definition

ilDBPdo::$field_definition
protected

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

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

◆ $host

ilDBPdo::$host = ''
protected

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

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

◆ $limit

ilDBPdo::$limit = null
protected

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

Referenced by appendLimit(), and setLimit().

◆ $manager

ilDBPdo::$manager
protected

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

Referenced by addUniqueConstraint(), and loadModule().

◆ $offset

ilDBPdo::$offset = null
protected

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

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

◆ $password

ilDBPdo::$password = ''
protected

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

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

◆ $pdo

ilDBPdo::$pdo
protected

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

◆ $port

ilDBPdo::$port = 3306
protected

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

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

◆ $reverse

ilDBPdo::$reverse
protected

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

Referenced by loadModule().

◆ $storage_engine

ilDBPdo::$storage_engine = 'MyISAM'
protected

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

Referenced by getStorageEngine(), and setStorageEngine().

◆ $username

ilDBPdo::$username = ''
protected

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

Referenced by getUsername(), and setUsername().

◆ FEATURE_FULLTEXT

const ilDBPdo::FEATURE_FULLTEXT = 'fulltext'

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

◆ FEATURE_SLAVE

const ilDBPdo::FEATURE_SLAVE = 'slave'

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

◆ FEATURE_TRANSACTIONS

const ilDBPdo::FEATURE_TRANSACTIONS = 'transactions'

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


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