ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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::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::AUTOQUERY_INSERT, $where=false, $types=null, $result_types=ilDBConstants::PREPARE_MANIP)
 
 buildManipSQL ($table, $table_fields, $mode, $where=false)
 

Protected Attributes

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

Detailed Description

Member Function Documentation

◆ addFulltextIndex()

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

Implements ilDBInterface.

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

References constraintName(), and query().

Referenced by addIndex().

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

References $f, addFulltextIndex(), constraintName(), and supportsFulltext().

876  {
877  assert(is_array($fields));
878  $this->field_definition->checkIndexName($index_name);
879 
880  $definition_fields = array();
881  foreach ($fields as $f) {
882  $definition_fields[$f] = array();
883  }
884  $definition = array(
885  'fields' => $definition_fields,
886  );
887 
888  if (!$fulltext) {
889  $this->manager->createIndex($table_name, $this->constraintName($table_name, $index_name), $definition);
890  } else {
891  if ($this->supportsFulltext()) {
892  $this->addFulltextIndex($table_name, $fields, $index_name); // TODO
893  }
894  }
895 
896  return true;
897  }
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 366 of file class.ilDBPdo.php.

References $f, constraintName(), and getPrimaryKeyIdentifier().

367  {
368  assert(is_array($primary_keys));
369 
370  $fields = array();
371  foreach ($primary_keys as $f) {
372  $fields[$f] = array();
373  }
374  $definition = array(
375  'primary' => true,
376  'fields' => $fields,
377  );
378  $this->manager->createConstraint($table_name, $this->constraintName($table_name, $this->getPrimaryKeyIdentifier()), $definition);
379 
380  return true;
381  }
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 463 of file class.ilDBPdo.php.

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

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

References $f, $manager, $name, $table, checkIndexName(), and constraintName().

1898  {
1899  assert(is_array($fields));
1901 
1902  // check index name
1903  if (!$this->checkIndexName($name)) {
1904  throw new ilDatabaseException("ilDB Error: addUniqueConstraint(" . $table . "," . $name . ")");
1905  }
1906 
1907  $fields_corrected = array();
1908  foreach ($fields as $f) {
1909  $fields_corrected[$f] = array();
1910  }
1911  $definition = array(
1912  'unique' => true,
1913  'fields' => $fields_corrected,
1914  );
1915 
1916  return $manager->createConstraint($table, $this->constraintName($table, $name), $definition);
1917  }
Class ilDatabaseException.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
checkIndexName($name)
if(empty($password)) $table
Definition: pwgen.php:24
+ Here is the call graph for this function:

◆ appendLimit()

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

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

References $limit, and $query.

Referenced by query().

1553  {
1554  if ($this->limit !== null && $this->offset !== null) {
1555  $query .= ' LIMIT ' . (int) $this->offset . ', ' . (int) $this->limit;
1556  $this->limit = null;
1557  $this->offset = null;
1558 
1559  return $query;
1560  }
1561 
1562  return $query;
1563  }
$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 2063 of file class.ilDBPdo.php.

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

2064  {
2065  $fields_values = (array) $fields;
2066  if ($mode == ilDBConstants::AUTOQUERY_INSERT) {
2067  if (!empty($fields_values)) {
2068  $keys = $fields_values;
2069  } else {
2070  $keys = array();
2071  }
2072  } else {
2073  $keys = array_keys($fields_values);
2074  }
2075  $params = array_values($fields_values);
2076  if (empty($params)) {
2077  $query = $this->buildManipSQL($tablename, $keys, $mode, $where);
2078  $result = $this->pdo->query($query);
2079  } else {
2080  $stmt = $this->autoPrepare($tablename, $keys, $mode, $where, $types, $result_types);
2081  $this->execute($stmt);
2082  $this->free($stmt);
2083  $result = $stmt;
2084  }
2085 
2086  return $result;
2087  }
autoPrepare($table, $table_fields, $mode=ilDBConstants::AUTOQUERY_INSERT, $where=false, $types=null, $result_types=ilDBConstants::PREPARE_MANIP)
$result
$stmt
execute($stmt, $data=array())
$keys
$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 2099 of file class.ilDBPdo.php.

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

Referenced by autoExecute().

2100  {
2101  $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
2102 
2103  return $this->prepare($query, $types, $result_types);
2104  }
$query
buildManipSQL($table, $table_fields, $mode, $where=false)
if(empty($password)) $table
Definition: pwgen.php:24
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 1696 of file class.ilDBPdo.php.

References supports().

Referenced by ilDBPdoPostgreSQL\lockTables().

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

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

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

Referenced by autoExecute(), and autoPrepare().

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

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

◆ checkColumn()

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

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

References checkColumnDefinition(), and checkColumnName().

Referenced by checkTableColumns().

326  {
327  if (!$this->checkColumnName($a_col)) {
328  return false;
329  }
330 
331  if (!$this->checkColumnDefinition($a_def)) {
332  return false;
333  }
334 
335  return true;
336  }
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 344 of file class.ilDBPdo.php.

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

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

◆ checkColumnName()

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

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

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

355  {
356  return $this->field_definition->checkColumnName($a_name);
357  }
+ Here is the caller graph for this function:

◆ checkIndexName()

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

Implements ilDBPdoInterface.

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

References $name, and getFieldDefinition().

Referenced by addUniqueConstraint().

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

References $def, and checkColumn().

Referenced by createTable().

309  {
310  foreach ($a_cols as $col => $def) {
311  if (!$this->checkColumn($col, $def)) {
312  return false;
313  }
314  }
315 
316  return true;
317  }
checkColumn($a_col, $a_def)
$def
Definition: croninfo.php:21
+ 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 1672 of file class.ilDBPdo.php.

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

1673  {
1674  return $this->field_definition->checkTableName($a_name);
1675  }
+ Here is the caller graph for this function:

◆ commit()

ilDBPdo::commit ( )
Returns
bool
Exceptions

Implements ilDBInterface.

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

References supports().

Referenced by ilDBPdoPostgreSQL\unlockTables().

1711  {
1712  if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1713  throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1714  }
1715 
1716  return $this->pdo->commit();
1717  }
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 1542 of file class.ilDBPdo.php.

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

◆ connect()

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

Implements ilDBInterface.

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

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

Referenced by createDatabase().

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

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

967  {
968  return $a_constraint;
969  }
+ 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 169 of file class.ilDBPdo.php.

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

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

References $start.

419  {
420  $this->manager->createSequence($table_name, $start);
421  }
$start
Definition: bench.php:8

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

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

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

Referenced by sanitizeMB4StringIfNotSupported().

2205  {
2206  return false;
2207  }
+ Here is the caller graph for this function:

◆ dropFulltextIndex()

ilDBPdo::dropFulltextIndex (   $a_table,
  $a_name 
)

Drop fulltext index.

Implements ilDBInterface.

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

References constraintName(), and query().

920  {
921  $i_name = $this->constraintName($a_table, $a_name) . "_idx";
922  $this->query("ALTER TABLE $a_table DROP FULLTEXT $i_name");
923  }
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 1739 of file class.ilDBPdo.php.

Referenced by dropIndexByFields().

1740  {
1741  return $this->manager->dropIndex($a_table, $a_name);
1742  }
+ 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 390 of file class.ilDBPdo.php.

References $def, and dropIndex().

391  {
392  foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
393  $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
394  $idx_fields = array_keys((array) $def['fields']);
395 
396  if ($idx_fields === $fields) {
397  return $this->dropIndex($table_name, $idx_name);
398  }
399  }
400 
401  return false;
402  }
$def
Definition: croninfo.php:21
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 2010 of file class.ilDBPdo.php.

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

◆ dropSequence()

ilDBPdo::dropSequence (   $table_name)
Parameters
$table_namestring

Implements ilDBInterface.

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

571  {
572  $this->manager->dropSequence($table_name);
573  }

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

References loadModule(), and ilDBConstants\MODULE_MANAGER.

Referenced by createTable().

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

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

◆ dropUniqueConstraint()

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

Implements ilDBPdoInterface.

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

References constraintName().

Referenced by dropUniqueConstraintByFields().

1926  {
1927  return $this->manager->dropConstraint($a_table, $this->constraintName($a_table, $a_name), false);
1928  }
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 1936 of file class.ilDBPdo.php.

References $c, $f, and dropUniqueConstraint().

1937  {
1938  $analyzer = new ilDBAnalyzer();
1939  $cons = $analyzer->getConstraintsInformation($a_table);
1940  foreach ($cons as $c) {
1941  if ($c["type"] == "unique" && count($a_fields) == count($c["fields"])) {
1942  $all_in = true;
1943  foreach ($a_fields as $f) {
1944  if (!isset($c["fields"][$f])) {
1945  $all_in = false;
1946  }
1947  }
1948  if ($all_in) {
1949  return $this->dropUniqueConstraint($a_table, $c['name']);
1950  }
1951  }
1952  }
1953 
1954  return false;
1955  }
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 1414 of file class.ilDBPdo.php.

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

1415  {
1416  $this->pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $a_status);
1417  }
+ 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 1197 of file class.ilDBPdo.php.

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

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

1827  {
1828  return $value;
1829  }

◆ escapePattern()

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

Implements ilDBPdoInterface.

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

References $text.

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

◆ executeMultiple()

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

Implements ilDBPdoInterface.

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

References $i, and $stmt.

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

◆ fetchAssoc()

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

Implements ilDBInterface.

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

References $res.

Referenced by isFulltextIndex().

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

References $res.

Referenced by getDBVersion().

658  {
659  $res = $query_result->fetchObject();
660  if ($res == null) {
661  $query_result->closeCursor();
662 
663  return null;
664  }
665 
666  return $res;
667  }
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 2033 of file class.ilDBPdo.php.

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

◆ generateDSN()

ilDBPdo::generateDSN ( )

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

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

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

225  {
226  $port = $this->getPort() ? ";port=" . $this->getPort() : "";
227  $dbname = $this->getDbname() ? ';dbname=' . $this->getDbname() : '';
228  $host = $this->getHost();
229  $charset = ';charset=' . $this->getCharset();
230  $this->dsn = 'mysql:host=' . $host . $port . $dbname . $charset;
231  }
+ 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 138 of file class.ilDBPdo.php.

Referenced by getAttributes().

139  {
140  return array();
141  }
+ Here is the caller graph for this function:

◆ getAllowedAttributes()

ilDBPdo::getAllowedAttributes ( )

Returns
array

Implements ilDBInterface.

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

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

◆ getAttributes()

ilDBPdo::getAttributes ( )
protected
Returns
array

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

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

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

125  {
127  foreach ($this->getAdditionalAttributes() as $k => $v) {
128  $options[$k] = $v;
129  }
130 
131  return $options;
132  }
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 1246 of file class.ilDBPdo.php.

References $charset.

Referenced by generateDSN().

1247  {
1248  return $this->charset;
1249  }
+ Here is the caller graph for this function:

◆ getDbname()

ilDBPdo::getDbname ( )
Returns
string

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

References $dbname.

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

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

◆ getDBType()

ilDBPdo::getDBType ( )
Returns
string

Implements ilDBInterface.

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

References $db_type.

985  {
986  return $this->db_type;
987  }

◆ getDBVersion()

ilDBPdo::getDBVersion ( )
Returns
string
Exceptions
ilDatabaseException

Implements ilDBPdoInterface.

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

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

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

References $dsn.

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

976  {
977  return $this->dsn;
978  }
+ Here is the caller graph for this function:

◆ getFieldDefinition()

ilDBPdo::getFieldDefinition ( )
Returns
ilDBPdoFieldDefinition

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

References $field_definition.

Referenced by checkIndexName().

148  {
150  }
+ Here is the caller graph for this function:

◆ getHost()

ilDBPdo::getHost ( )
Returns
string

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

References $host.

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

1211  {
1212  return $this->host;
1213  }
+ Here is the caller graph for this function:

◆ getIndexName()

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

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

References ilDBPdoFieldDefinition\INDEX_FORMAT.

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

◆ getLastErrorCode()

ilDBPdo::getLastErrorCode ( )
Returns
int

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

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

◆ getPassword()

ilDBPdo::getPassword ( )
Returns
string

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

References $password.

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

1283  {
1284  return $this->password;
1285  }
+ Here is the caller graph for this function:

◆ getPort()

ilDBPdo::getPort ( )
Returns
int

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

References $port.

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

1301  {
1302  return $this->port;
1303  }
+ Here is the caller graph for this function:

◆ getPrimaryKeyIdentifier()

ilDBPdo::getPrimaryKeyIdentifier ( )
Returns
string

Implements ilDBInterface.

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

Referenced by addPrimaryKey().

409  {
410  return "PRIMARY";
411  }
+ Here is the caller graph for this function:

◆ getSequenceName()

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

Implements ilDBInterface.

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

References ilDBPdoFieldDefinition\SEQUENCE_FORMAT.

Referenced by ilDBPdoMySQL\nextId().

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

◆ getServerVersion()

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

Implements ilDBPdoInterface.

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

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

◆ getStorageEngine()

ilDBPdo::getStorageEngine ( )
Returns
string

Implements ilDBInterface.

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

References $storage_engine.

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

◆ getUsername()

ilDBPdo::getUsername ( )
Returns
string

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

References $username.

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

1265  {
1266  return $this->username;
1267  }
+ 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 2213 of file class.ilDBPdo.php.

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

◆ in()

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

Implements ilDBInterface.

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

References $type, and $values.

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

◆ indexExistsByFields()

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

Implements ilDBInterface.

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

References $def.

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

◆ initFromIniFile()

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

Implements ilDBInterface.

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

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

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

Referenced by connect().

117  {
118  }
+ 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 634 of file class.ilDBPdo.php.

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

Referenced by ilDBPdoPostgreSQL\replace().

635  {
636  $real = array();
637  $fields = array();
638  foreach ($values as $key => $val) {
639  $real[] = $this->quote($val[1], $val[0]);
640  $fields[] = $this->quoteIdentifier($key);
641  }
642  $values = implode(",", $real);
643  $fields = implode(",", $fields);
644  $query = "INSERT INTO " . $table_name . " (" . $fields . ") VALUES (" . $values . ")";
645 
647 
648  return $this->pdo->exec($query);
649  }
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)
$values
$query
$key
Definition: croninfo.php:18
+ 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 929 of file class.ilDBPdo.php.

References fetchAssoc(), and query().

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

References $DIC, and ilDBPdoFieldDefinition\isReserved().

1683  {
1684  require_once('./Services/Database/classes/PDO/FieldDefinition/class.ilDBPdoMySQLFieldDefinition.php');
1685  global $DIC;
1686  $ilDBPdoMySQLFieldDefinition = new ilDBPdoMySQLFieldDefinition($DIC->database());
1687 
1688  return $ilDBPdoMySQLFieldDefinition->isReserved($a_word);
1689  }
global $DIC
Definition: saml.php:7
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 1135 of file class.ilDBPdo.php.

References $type.

1136  {
1137  return $this->manager->getQueryUtils()->like($column, $type, $value, $case_insensitive);
1138  }
$type

◆ listSequences()

ilDBPdo::listSequences ( )
Returns
array

Implements ilDBInterface.

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

Referenced by sequenceExists().

1532  {
1533  return $this->manager->listSequences();
1534  }
+ Here is the caller graph for this function:

◆ listTables()

ilDBPdo::listTables ( )
Returns
array

Implements ilDBInterface.

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

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

1489  {
1490  return $this->manager->listTables();
1491  }
+ Here is the caller graph for this function:

◆ loadModule()

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

Implements ilDBInterface.

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

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

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

1499  {
1500  switch ($module) {
1502  return $this->manager;
1504  return $this->reverse;
1505  }
1506  }
if($modEnd===false) $module
Definition: module.php:59
+ 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 1572 of file class.ilDBPdo.php.

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

◆ lockTables()

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

Implements ilDBInterface.

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

References $DIC.

1021  {
1022  assert(is_array($tables));
1023 
1024  $lock = $this->manager->getQueryUtils()->lock($tables);
1025  global $DIC;
1026  $ilLogger = $DIC->logger()->root();
1027  if ($ilLogger instanceof ilLogger) {
1028  $ilLogger->log('ilDB::lockTables(): ' . $lock);
1029  }
1030 
1031  $this->pdo->exec($lock);
1032  }
global $DIC
Definition: saml.php:7
Component logger with individual log levels by component id.

◆ lower()

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

Implements ilDBInterface.

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

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

◆ manipulate()

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

Implements ilDBInterface.

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

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

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

760  {
761  global $DIC;
762  $ilBench = $DIC['ilBench'];
763  try {
765  if ($ilBench instanceof ilBenchmark) {
766  $ilBench->startDbBench($query);
767  }
768  $r = $this->pdo->exec($query);
769  if ($ilBench instanceof ilBenchmark) {
770  $ilBench->stopDbBench();
771  }
772  } catch (PDOException $e) {
773  throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query);
774  }
775 
776  return $r;
777  }
sanitizeMB4StringIfNotSupported($query)
string to sanitize, all MB4-Characters like emojis will re replaced with ???string sanitized query ...
global $DIC
Definition: saml.php:7
Class ilDatabaseException.
$r
Definition: example_031.php:79
$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:

◆ manipulateF()

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

Implements ilDBInterface.

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

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

Referenced by replace(), and update().

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

1856  {
1857  return array();
1858  }

◆ migrateAllTablesToEngine()

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

Implements ilDBPdoInterface.

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

1847  {
1848  return array();
1849  }

◆ modifyTableColumn()

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

Implements ilDBInterface.

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

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

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

Implements ilDBInterface.

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

References $rows, $stmt, and tableExists().

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

◆ now()

ilDBPdo::now ( )
Returns
string the now statement

Implements ilDBInterface.

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

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

◆ numRows()

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

Implements ilDBInterface.

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

804  {
805  return $query_result->rowCount();
806  }

◆ prepare()

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

Implements ilDBInterface.

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

References $query.

Referenced by autoPrepare().

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

References $query.

Referenced by update().

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

◆ query()

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

Implements ilDBInterface.

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

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

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

519  {
520  global $DIC;
521  $ilBench = $DIC['ilBench'];
522 
523  $query = $this->appendLimit($query);
524 
525  try {
526  if ($ilBench instanceof ilBenchmark) {
527  $ilBench->startDbBench($query);
528  }
529  $res = $this->pdo->query($query);
530  if ($ilBench instanceof ilBenchmark) {
531  $ilBench->stopDbBench();
532  }
533  } catch (PDOException $e) {
534  throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query);
535  }
536 
537  $err = $this->pdo->errorCode();
538  if ($err != PDO::ERR_NONE) {
539  $info = $this->pdo->errorInfo();
540  $info_message = $info[2];
541  throw new ilDatabaseException($info_message . ' QUERY: ' . $query);
542  }
543 
544  return new ilPDOStatement($res);
545  }
global $DIC
Definition: saml.php:7
Class ilPDOStatement is a Wrapper Class for PDOStatement.
Class ilDatabaseException.
foreach($_POST as $key=> $value) $res
$query
appendLimit($query)
global $ilBench
Definition: ilias.php:18
performance measurement class
$info
Definition: index.php:5
+ 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 1769 of file class.ilDBPdo.php.

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

Referenced by ilDBPdoMySQL\migrateAllTablesToEngine().

1770  {
1771  switch ($type) {
1773  $type = PDO::FETCH_ASSOC;
1774  break;
1776  $type = PDO::FETCH_OBJ;
1777  break;
1778  default:
1779  $type = PDO::FETCH_ASSOC;
1780  break;
1781  }
1782 
1783  return $this->pdo->query($query, PDO::FETCH_ASSOC)->fetchAll(PDO::FETCH_COLUMN, $colnum);
1784  }
$type
$query
+ Here is the caller graph for this function:

◆ queryF()

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

Implements ilDBInterface.

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

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

1066  {
1067  if (!is_array($types) || !is_array($values) || count($types) != count($values)) {
1068  throw new ilDatabaseException("ilDB::queryF: Types and values must be arrays of same size. ($query)");
1069  }
1070  $quoted_values = array();
1071  foreach ($types as $k => $t) {
1072  $quoted_values[] = $this->quote($values[$k], $t);
1073  }
1074  $query = vsprintf($query, $quoted_values);
1075 
1076  return $this->query($query);
1077  }
quote($value, $type=null)
Class ilDatabaseException.
query($query)
$values
$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 1793 of file class.ilDBPdo.php.

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

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

◆ quote()

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

Implements ilDBInterface.

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

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

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

816  {
817  if ($value === null) {
818  return 'NULL';
819  }
820 
821  $pdo_type = PDO::PARAM_STR;
822  switch ($type) {
826  if ($value === '') {
827  return 'NULL';
828  }
829  break;
831  $value = (int) $value;
832 
833  return $value;
834  break;
836  $pdo_type = PDO::PARAM_INT;
837  break;
839  default:
840  $pdo_type = PDO::PARAM_STR;
841  break;
842  }
843 
844  return $this->pdo->quote($value, $pdo_type);
845  }
$type
+ Here is the caller graph for this function:

◆ quoteIdentifier()

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

Implements ilDBInterface.

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

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

239  {
240  return '`' . $identifier . '`';
241  }
+ 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 1647 of file class.ilDBPdo.php.

References checkTableName().

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

References $def, $f, and checkColumnName().

602  {
603  // check table name
604  if (!$this->checkColumnName($column_new_name)) {
605  throw new ilDatabaseException("ilDB Error: renameTableColumn(" . $table_name . "," . $column_old_name . "," . $column_new_name . ")");
606  }
607 
608  $def = $this->reverse->getTableFieldDefinition($table_name, $column_old_name);
609 
610  $analyzer = new ilDBAnalyzer($this);
611  $best_alt = $analyzer->getBestDefinitionAlternative($def);
612  $def = $def[$best_alt];
613  unset($def["nativetype"]);
614  unset($def["mdb2type"]);
615 
616  $f["definition"] = $def;
617  $f["name"] = $column_new_name;
618 
619  $changes = array(
620  "rename" => array(
621  $column_old_name => $f,
622  ),
623  );
624 
625  return $this->manager->alterTable($table_name, $changes, false);
626  }
Class ilDatabaseException.
checkColumnName($a_name)
$def
Definition: croninfo.php:21
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 1158 of file class.ilDBPdo.php.

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

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

◆ rollback()

ilDBPdo::rollback ( )
Returns
bool
Exceptions

Implements ilDBInterface.

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

References supports().

1725  {
1726  if (!$this->supports(self::FEATURE_TRANSACTIONS)) {
1727  throw new ilDatabaseException("ilDB::beginTransaction: Transactions are not supported.");
1728  }
1729 
1730  return $this->pdo->rollBack();
1731  }
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 2185 of file class.ilDBPdo.php.

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

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

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

References listSequences().

1523  {
1524  return in_array($sequence, $this->listSequences());
1525  }
+ Here is the call graph for this function:

◆ setCharset()

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

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

References $charset.

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

◆ setDBHost()

ilDBPdo::setDBHost (   $host)
Parameters
$host

Implements ilDBInterface.

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

References $host, and setHost().

1346  {
1347  $this->setHost($host);
1348  }
setHost($host)
+ Here is the call graph for this function:

◆ setDbname()

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

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

References $dbname.

Referenced by createDatabase(), and initFromIniFile().

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

◆ setDBPassword()

ilDBPdo::setDBPassword (   $password)
Parameters
$password

Implements ilDBInterface.

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

References $password, and setPassword().

1337  {
1338  $this->setPassword($password);
1339  }
setPassword($password)
+ Here is the call graph for this function:

◆ setDBPort()

ilDBPdo::setDBPort (   $port)
Parameters
$port

Implements ilDBInterface.

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

References $port, and setPort().

1328  {
1329  $this->setPort($port);
1330  }
setPort($port)
+ Here is the call graph for this function:

◆ setDBType()

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

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

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

Referenced by initFromIniFile().

995  {
996  $this->db_type = $type;
997  }
$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 1318 of file class.ilDBPdo.php.

References $user, and setUsername().

1319  {
1320  $this->setUsername($user);
1321  }
setUsername($username)
$user
Definition: migrateto20.php:57
+ Here is the call graph for this function:

◆ setFieldDefinition()

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

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

References $field_definition.

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

◆ setHost()

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

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

References $host.

Referenced by initFromIniFile(), and setDBHost().

1220  {
1221  $this->host = $host;
1222  }
+ 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 1120 of file class.ilDBPdo.php.

References $limit, and $offset.

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

◆ setPassword()

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

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

References $password.

Referenced by initFromIniFile(), and setDBPassword().

1292  {
1293  $this->password = $password;
1294  }
+ Here is the caller graph for this function:

◆ setPort()

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

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

References $port.

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

1310  {
1311  $this->port = $port;
1312  }
+ Here is the caller graph for this function:

◆ setStorageEngine()

ilDBPdo::setStorageEngine (   $storage_engine)
Parameters
$storage_engine

Implements ilDBInterface.

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

References $storage_engine.

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

◆ setUsername()

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

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

References $username.

Referenced by initFromIniFile(), and setDBUser().

1274  {
1275  $this->username = $username;
1276  }
+ 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 1377 of file class.ilDBPdo.php.

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

◆ supports()

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

Implements ilDBInterface.

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

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

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

1471  {
1472  switch ($feature) {
1473  case self::FEATURE_TRANSACTIONS:
1474  return $this->supportsTransactions();
1475  case self::FEATURE_FULLTEXT:
1476  return $this->supportsFulltext();
1477  case self::FEATURE_SLAVE:
1478  return $this->supportsSlave();
1479  default:
1480  return false;
1481  }
1482  }
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 1864 of file class.ilDBPdo.php.

1865  {
1866  return false;
1867  }

◆ supportsEngineMigration()

ilDBPdo::supportsEngineMigration ( )
Returns
bool

Implements ilDBPdoInterface.

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

1874  {
1875  return false;
1876  }

◆ supportsFulltext()

ilDBPdo::supportsFulltext ( )
Returns
bool

Implements ilDBInterface.

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

Referenced by addIndex(), and supports().

1452  {
1453  return false;
1454  }
+ Here is the caller graph for this function:

◆ supportsSlave()

ilDBPdo::supportsSlave ( )
Returns
bool

Implements ilDBInterface.

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

Referenced by supports().

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

◆ supportsTransactions()

ilDBPdo::supportsTransactions ( )
Returns
bool

Implements ilDBInterface.

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

Referenced by supports().

1461  {
1462  return false;
1463  }
+ 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 446 of file class.ilDBPdo.php.

References loadModule(), and ilDBConstants\MODULE_MANAGER.

447  {
448  $fields = $this->loadModule(ilDBConstants::MODULE_MANAGER)->listTableFields($table_name);
449 
450  $in_array = in_array($column_name, $fields);
451 
452  return $in_array;
453  }
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 429 of file class.ilDBPdo.php.

References $result.

Referenced by nextId().

430  {
431  $result = $this->pdo->prepare("SHOW TABLES LIKE :table_name");
432  $result->execute(array('table_name' => $table_name));
433  $return = $result->rowCount();
434  $result->closeCursor();
435 
436  return $return > 0;
437  }
$result
+ 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 1983 of file class.ilDBPdo.php.

References $c, $f, and $table.

1984  {
1985  require_once('./Services/Database/classes/class.ilDBAnalyzer.php');
1986  $analyzer = new ilDBAnalyzer();
1987  $cons = $analyzer->getConstraintsInformation($table);
1988  foreach ($cons as $c) {
1989  if ($c["type"] == "unique" && count($fields) == count($c["fields"])) {
1990  $all_in = true;
1991  foreach ($fields as $f) {
1992  if (!isset($c["fields"][$f])) {
1993  $all_in = false;
1994  }
1995  }
1996  if ($all_in) {
1997  return true;
1998  }
1999  }
2000  }
2001 
2002  return false;
2003  }
if(empty($password)) $table
Definition: pwgen.php:24
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 2042 of file class.ilDBPdo.php.

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

◆ unlockTables()

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

Implements ilDBInterface.

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

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

◆ update()

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

Implements ilDBInterface.

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

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

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

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

◆ useSlave()

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

TODO

Implements ilDBInterface.

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

1109  {
1110  return false;
1111  }

Field Documentation

◆ $attributes

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

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

Referenced by addTableColumn(), and getAttributes().

◆ $charset

ilDBPdo::$charset = 'utf8'
protected

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

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

◆ $db_type

ilDBPdo::$db_type = ''
protected

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

Referenced by getDBType().

◆ $dbname

ilDBPdo::$dbname = ''
protected

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

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

◆ $dsn

ilDBPdo::$dsn = ''
protected

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

Referenced by getDSN().

◆ $error_code

ilDBPdo::$error_code = 0
protected

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

Referenced by getLastErrorCode().

◆ $field_definition

ilDBPdo::$field_definition
protected

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

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

◆ $host

ilDBPdo::$host = ''
protected

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

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

◆ $limit

ilDBPdo::$limit = null
protected

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

Referenced by appendLimit(), and setLimit().

◆ $manager

ilDBPdo::$manager
protected

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

Referenced by addUniqueConstraint(), and loadModule().

◆ $offset

ilDBPdo::$offset = null
protected

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

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

◆ $password

ilDBPdo::$password = ''
protected

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

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

◆ $pdo

ilDBPdo::$pdo
protected

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

◆ $port

ilDBPdo::$port = 3306
protected

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

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

◆ $reverse

ilDBPdo::$reverse
protected

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

Referenced by loadModule().

◆ $storage_engine

ilDBPdo::$storage_engine = 'MyISAM'
protected

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

Referenced by getStorageEngine(), and setStorageEngine().

◆ $username

ilDBPdo::$username = ''
protected

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

Referenced by getUsername(), and setUsername().

◆ FEATURE_FULLTEXT

const ilDBPdo::FEATURE_FULLTEXT = 'fulltext'

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

◆ FEATURE_SLAVE

const ilDBPdo::FEATURE_SLAVE = 'slave'

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

◆ FEATURE_TRANSACTIONS

const ilDBPdo::FEATURE_TRANSACTIONS = 'transactions'

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


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