ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilDBPdo Class Reference

Class pdoDB. More...

+ Inheritance diagram for ilDBPdo:
+ Collaboration diagram for ilDBPdo:

Public Member Functions

 connect ($return_false_for_error=false)
 
 initHelpers ()
 
 getFieldDefinition ()
 
 setFieldDefinition ($field_definition)
 
 createDatabase ($a_name, $a_charset="utf8", $a_collation="")
 
 getLastErrorCode ()
 
 initFromIniFile ($tmpClientIniFile=null)
 
 generateDSN ()
 
 quoteIdentifier ($identifier, $check_option=false)
 
 nextId ($table_name)
 
 createTable ($table_name, $fields, $drop_table=false, $ignore_erros=false)
 
 checkColumnName ($a_name)
 
 addPrimaryKey ($table_name, $primary_keys)
 
 dropIndexByFields ($table_name, $fields)
 
 getPrimaryKeyIdentifier ()
 
 createSequence ($table_name, $start=1)
 
 tableExists ($table_name)
 
 tableColumnExists ($table_name, $column_name)
 
 addTableColumn ($table_name, $column_name, $attributes)
 
 dropTable ($table_name, $error_if_not_existing=true)
 
 query ($query)
 
 dropSequence ($table_name)
 
 dropTableColumn ($table_name, $column_name)
 
 renameTableColumn ($table_name, $column_old_name, $column_new_name)
 
 insert ($table_name, $values)
 
 fetchObject ($query_result)
 
 update ($table_name, $columns, $where)
 
 manipulate ($query)
 
 fetchAssoc ($query_result)
 
 numRows ($query_result)
 
 quote ($value, $type=null)
 
 indexExistsByFields ($table_name, $fields)
 
 addIndex ($table_name, $fields, $index_name='', $fulltext=false)
 
 addFulltextIndex ($a_table, $a_fields, $a_name="in")
 
 dropFulltextIndex ($a_table, $a_name)
 Drop fulltext index. More...
 
 isFulltextIndex ($a_table, $a_name)
 Is index a fulltext index? More...
 
 getIndexName ($index_name_base)
 
 getSequenceName ($table_name)
 
 constraintName ($a_table, $a_constraint)
 Determine contraint name by table name and constraint name. More...
 
 getDSN ()
 
 getDBType ()
 
 setDBType ($type)
 
 lockTables ($tables)
 
 unlockTables ()
 
 in ($field, $values, $negate=false, $type="")
 
 queryF ($query, $types, $values)
 
 manipulateF ($query, $types, $values)
 
 useSlave ($bool)
 
 setLimit ($limit, $offset=0)
 Set the Limit for the next Query. More...
 
 like ($column, $type, $value="?", $case_insensitive=true)
 
 now ()
 
 replace ($table, $primaryKeys, $otherColumns)
 Replace into method. More...
 
 equals ($columns, $value, $type, $emptyOrNull=false)
 
 getHost ()
 
 setHost ($host)
 
 getDbname ()
 
 setDbname ($dbname)
 
 getCharset ()
 
 setCharset ($charset)
 
 getUsername ()
 
 setUsername ($username)
 
 getPassword ()
 
 setPassword ($password)
 
 getPort ()
 
 setPort ($port)
 
 setDBUser ($user)
 
 setDBPort ($port)
 
 setDBPassword ($password)
 
 setDBHost ($host)
 
 upper ($a_exp)
 
 lower ($a_exp)
 
 substr ($a_exp, $a_pos=1, $a_len=-1)
 
 prepareManip ($query, $types=null)
 
 prepare ($query, $types=null, $result_types=null)
 
 enableResultBuffering ($a_status)
 
 supportsSlave ()
 
 supportsFulltext ()
 
 supportsTransactions ()
 
 supports ($feature)
 
 listTables ()
 
 loadModule ($module)
 
 getAllowedAttributes ()
 
Returns
array
More...
 
 sequenceExists ($sequence)
 
 listSequences ()
 
 concat (array $values, $allow_null=true)
 
 locate ($a_needle, $a_string, $a_start_pos=1)
 
 modifyTableColumn ($table, $a_column, $a_attributes)
 
 renameTable ($a_name, $a_new_name)
 
 checkTableName ($a_name)
 
 beginTransaction ()
 
 commit ()
 
 rollback ()
 
 dropIndex ($a_table, $a_name="i1")
 
 setStorageEngine ($storage_engine)
 
 getStorageEngine ()
 
 queryCol ($query, $type=PDO::FETCH_ASSOC, $colnum=0)
 
 queryRow ($query, $types=null, $fetchmode=ilDBConstants::FETCHMODE_DEFAULT)
 
 getServerVersion ($native=false)
 
 escape ($value, $escape_wildcards=false)
 
 escapePattern ($text)
 
 migrateAllTablesToEngine ($engine=ilDBConstants::MYSQL_ENGINE_INNODB)
 
 migrateAllTablesToCollation ($collation=ilDBConstants::MYSQL_COLLATION_UTF8MB4)
 
 supportsCollationMigration ()
 
 supportsEngineMigration ()
 
 checkIndexName ($name)
 
 addUniqueConstraint ($table, $fields, $name="con")
 
 dropUniqueConstraint ($a_table, $a_name="con")
 
 dropUniqueConstraintByFields ($a_table, $a_fields)
 
 getLastInsertId ()
 
 buildAtomQuery ()
 
 uniqueConstraintExists ($table, array $fields)
 
 dropPrimaryKey ($table_name)
 
 executeMultiple ($stmt, $a_data)
 
 fromUnixtime ($a_expr, $a_to_text=true)
 
 unixTimestamp ()
 
 autoExecute ($tablename, $fields, $mode=ilDBConstants::MDB2_AUTOQUERY_INSERT, $where=false)
 Generate an insert, update or delete query and call prepare() and execute() on it. More...
 
 getDBVersion ()
 
 sanitizeMB4StringIfNotSupported ($query)
 
Parameters
$querystring to sanitize, all MB4-Characters like emojis will re replaced with ???
Returns
string sanitized query
More...
 
 doesCollationSupportMB4Strings ()
 
 groupConcat ($a_field_name, $a_seperator=",", $a_order=null)
 
Parameters
string$a_field_name
string$a_seperator
string$a_order
Returns
string
More...
 
 cast ($a_field_name, $a_dest_type)
 
Parameters
string$a_field_name
string$a_dest_type
Returns
string;
More...
 
- Public Member Functions inherited from ilDBInterface
 fetchAll ($query_result, $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
 
 substr ($a_exp)
 
 execute ($stmt, $data=array())
 
 free ($a_st)
 

Static Public Member Functions

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

Data Fields

const FEATURE_TRANSACTIONS = 'transactions'
 
const FEATURE_FULLTEXT = 'fulltext'
 
const FEATURE_SLAVE = 'slave'
 

Protected Member Functions

 initSQLMode ()
 
 getAttributes ()
 
 getAdditionalAttributes ()
 
 checkTableColumns ($a_cols)
 
 checkColumn ($a_col, $a_def)
 
 checkColumnDefinition ($a_def, $a_modify_mode=false)
 
 appendLimit ($query)
 
 autoPrepare ($table, $table_fields, $mode=ilDBConstants::MDB2_AUTOQUERY_INSERT, $where=false, $types=null, $result_types=ilDBConstants::MDB2_PREPARE_MANIP)
 
 buildManipSQL ($table, $table_fields, $mode, $where=false)
 

Protected Attributes

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

Detailed Description

Member Function Documentation

◆ addFulltextIndex()

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

Implements ilDBInterface.

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

References constraintName(), and query().

Referenced by addIndex().

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

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

878  {
879  assert(is_array($fields));
880  $this->field_definition->checkIndexName($index_name);
881 
882  $definition_fields = array();
883  foreach ($fields as $f) {
884  $definition_fields[$f] = array();
885  }
886  $definition = array(
887  'fields' => $definition_fields,
888  );
889 
890  if (!$fulltext) {
891  $this->manager->createIndex($table_name, $this->constraintName($table_name, $index_name), $definition);
892  } else {
893  if ($this->supportsFulltext()) {
894  $this->addFulltextIndex($table_name, $fields, $index_name); // TODO
895  }
896  }
897 
898  return true;
899  }
addFulltextIndex($a_table, $a_fields, $a_name="in")
Create styles array
The data for the language used.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
+ Here is the call graph for this function:

◆ addPrimaryKey()

ilDBPdo::addPrimaryKey (   $table_name,
  $primary_keys 
)
Parameters
string$table_name
array$primary_keys
Returns
bool
Exceptions

Implements ilDBInterface.

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

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

369  {
370  assert(is_array($primary_keys));
371 
372  $fields = array();
373  foreach ($primary_keys as $f) {
374  $fields[$f] = array();
375  }
376  $definition = array(
377  'primary' => true,
378  'fields' => $fields,
379  );
380  $this->manager->createConstraint($table_name, $this->constraintName($table_name, $this->getPrimaryKeyIdentifier()), $definition);
381 
382  return true;
383  }
Create styles array
The data for the language used.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
getPrimaryKeyIdentifier()
+ Here is the call graph for this function:

◆ addTableColumn()

ilDBPdo::addTableColumn (   $table_name,
  $column_name,
  $attributes 
)
Parameters
string$table_name
string$column_name
array$attributes
Returns
bool
Exceptions

Implements ilDBInterface.

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

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

466  {
467  if (!$this->checkColumnName($column_name)) {
468  throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
469  }
470  if (!$this->checkColumnDefinition($attributes)) {
471  throw new ilDatabaseException("ilDB Error: addTableColumn(" . $table_name . ", " . $column_name . ")");
472  }
473 
474  $changes = array(
475  "add" => array(
476  $column_name => $attributes,
477  ),
478  );
479 
480  return $this->manager->alterTable($table_name, $changes, false);
481  }
Class ilDatabaseException.
checkColumnName($a_name)
Create styles array
The data for the language used.
checkColumnDefinition($a_def, $a_modify_mode=false)
+ Here is the call graph for this function:

◆ addUniqueConstraint()

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

Implements ilDBPdoInterface.

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

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

1899  {
1900  assert(is_array($fields));
1902 
1903  // check index name
1904  if (!$this->checkIndexName($name)) {
1905  throw new ilDatabaseException("ilDB Error: addUniqueConstraint(" . $table . "," . $name . ")");
1906  }
1907 
1908  $fields_corrected = array();
1909  foreach ($fields as $f) {
1910  $fields_corrected[$f] = array();
1911  }
1912  $definition = array(
1913  'unique' => true,
1914  'fields' => $fields_corrected,
1915  );
1916 
1917  return $manager->createConstraint($table, $this->constraintName($table, $name), $definition);
1918  }
Class ilDatabaseException.
if($format !==null) $name
Definition: metadata.php:146
Create styles array
The data for the language used.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
checkIndexName($name)
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 1553 of file class.ilDBPdo.php.

References $limit, and $query.

Referenced by query().

1554  {
1555  if ($this->limit !== null && $this->offset !== null) {
1556  $query .= ' LIMIT ' . (int) $this->offset . ', ' . (int) $this->limit;
1557  $this->limit = null;
1558  $this->offset = null;
1559 
1560  return $query;
1561  }
1562 
1563  return $query;
1564  }
$query
+ Here is the caller graph for this function:

◆ autoExecute()

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

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

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

Implements ilDBPdoInterface.

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

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

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

◆ autoPrepare()

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

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

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

Referenced by autoExecute().

2101  {
2102  $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
2103 
2104  return $this->prepare($query, $types, $result_types);
2105  }
$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 1697 of file class.ilDBPdo.php.

References supports().

Referenced by ilDBPdoPostgreSQL\lockTables().

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

1972  {
1973  require_once('./Services/Database/classes/Atom/class.ilAtomQueryLock.php');
1974 
1975  return new ilAtomQueryLock($this);
1976  }
Class ilAtomQueryLock.

◆ buildManipSQL()

ilDBPdo::buildManipSQL (   $table,
  $table_fields,
  $mode,
  $where = false 
)
protected
Parameters
$table
$table_fields
$mode
bool$where
Returns
string
Exceptions

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

References $cols, $key, $table, ilDBConstants\MDB2_AUTOQUERY_DELETE, ilDBConstants\MDB2_AUTOQUERY_INSERT, ilDBConstants\MDB2_AUTOQUERY_SELECT, ilDBConstants\MDB2_AUTOQUERY_UPDATE, and quoteIdentifier().

Referenced by autoExecute(), and autoPrepare().

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

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

◆ checkColumn()

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

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

References checkColumnDefinition(), and checkColumnName().

Referenced by checkTableColumns().

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

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

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

◆ checkColumnName()

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

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

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

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

◆ checkIndexName()

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

Implements ilDBPdoInterface.

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

References $name, and getFieldDefinition().

Referenced by addUniqueConstraint().

1886  {
1887  return $this->getFieldDefinition()->checkIndexName($name);
1888  }
if($format !==null) $name
Definition: metadata.php:146
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 310 of file class.ilDBPdo.php.

References $def, and checkColumn().

Referenced by createTable().

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

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

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

◆ commit()

ilDBPdo::commit ( )
Returns
bool
Exceptions

Implements ilDBInterface.

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

References supports().

Referenced by ilDBPdoPostgreSQL\unlockTables().

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

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

◆ connect()

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

Implements ilDBInterface.

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

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

Referenced by createDatabase().

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

◆ constraintName()

ilDBPdo::constraintName (   $a_table,
  $a_constraint 
)

Determine contraint name by table name and constraint name.

In MySQL these are "unique" per table, but they must be "globally" unique in oracle. (so this one is overwritten there)

Implements ilDBInterface.

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

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

970  {
971  return $a_constraint;
972  }
+ Here is the caller graph for this function:

◆ createDatabase()

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

Implements ilDBInterface.

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

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

178  {
179  $this->setDbname(null);
180  $this->generateDSN();
181  $this->connect(true);
182  try {
183  return $this->query($this->manager->getQueryUtils()->createDatabase($a_name, $a_charset, $a_collation));
184  } catch (PDOException $e) {
185  return false;
186  }
187  }
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 420 of file class.ilDBPdo.php.

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

◆ createTable()

ilDBPdo::createTable (   $table_name,
  $fields,
  $drop_table = false,
  $ignore_erros = false 
)
Parameters
$table_name
$fields
bool$drop_table
bool$ignore_erros
Returns
mixed
Exceptions

Implements ilDBInterface.

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

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

287  {
288  // check table name
289  if (!$this->checkTableName($table_name) && !$ignore_erros) {
290  throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
291  }
292 
293  // check definition array
294  if (!$this->checkTableColumns($fields) && !$ignore_erros) {
295  throw new ilDatabaseException("ilDB Error: createTable(" . $table_name . ")");
296  }
297 
298  if ($drop_table) {
299  $this->dropTable($table_name, false);
300  }
301 
302  return $this->manager->createTable($table_name, $fields, array());
303  }
checkTableName($a_name)
Class ilDatabaseException.
dropTable($table_name, $error_if_not_existing=true)
checkTableColumns($a_cols)
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ doesCollationSupportMB4Strings()

ilDBPdo::doesCollationSupportMB4Strings ( )

Implements ilDBInterface.

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

Referenced by sanitizeMB4StringIfNotSupported().

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

◆ dropFulltextIndex()

ilDBPdo::dropFulltextIndex (   $a_table,
  $a_name 
)

Drop fulltext index.

Implements ilDBInterface.

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

References constraintName(), and query().

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

Referenced by dropIndexByFields().

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

References $def, array, and dropIndex().

393  {
394  foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
395  $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
396  $idx_fields = array_keys((array) $def['fields']);
397 
398  if ($idx_fields === $fields) {
399  return $this->dropIndex($table_name, $idx_name);
400  }
401  }
402 
403  return false;
404  }
Create styles array
The data for the language used.
$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 2011 of file class.ilDBPdo.php.

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

◆ dropSequence()

ilDBPdo::dropSequence (   $table_name)
Parameters
$table_namestring

Implements ilDBInterface.

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

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

◆ dropTable()

ilDBPdo::dropTable (   $table_name,
  $error_if_not_existing = true 
)
Parameters
$table_name
bool$error_if_not_existing
Returns
bool
Exceptions

Implements ilDBInterface.

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

References loadModule(), and ilDBConstants\MODULE_MANAGER.

Referenced by createTable().

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

References array.

585  {
586  $changes = array(
587  "remove" => array(
588  $column_name => array(),
589  ),
590  );
591 
592  return $this->manager->alterTable($table_name, $changes, false);
593  }
Create styles array
The data for the language used.

◆ dropUniqueConstraint()

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

Implements ilDBPdoInterface.

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

References constraintName().

Referenced by dropUniqueConstraintByFields().

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

References dropUniqueConstraint().

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

◆ enableResultBuffering()

ilDBPdo::enableResultBuffering (   $a_status)
Parameters
$a_status

Implements ilDBInterface.

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

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

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

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

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

1828  {
1829  return $value;
1830  }

◆ escapePattern()

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

Implements ilDBPdoInterface.

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

References $text.

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

◆ executeMultiple()

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

Implements ilDBPdoInterface.

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

References $i.

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

◆ fetchAssoc()

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

Implements ilDBInterface.

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

References $res.

Referenced by isFulltextIndex().

788  {
789  $res = $query_result->fetch(PDO::FETCH_ASSOC);
790  if ($res == null) {
791  $query_result->closeCursor();
792 
793  return null;
794  }
795 
796  return $res;
797  }
foreach($_POST as $key=> $value) $res
+ Here is the caller graph for this function:

◆ fetchObject()

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

Implements ilDBInterface.

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

References $res.

Referenced by getDBVersion().

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

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

◆ generateDSN()

ilDBPdo::generateDSN ( )

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

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

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

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

References array.

Referenced by getAttributes().

147  {
148  return array();
149  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getAllowedAttributes()

ilDBPdo::getAllowedAttributes ( )

Returns
array

Implements ilDBInterface.

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

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

◆ getAttributes()

ilDBPdo::getAttributes ( )
protected
Returns
array

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

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

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

133  {
135  foreach ($this->getAdditionalAttributes() as $k => $v) {
136  $options[$k] = $v;
137  }
138 
139  return $options;
140  }
getAdditionalAttributes()
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCharset()

ilDBPdo::getCharset ( )
Returns
string

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

References $charset.

Referenced by generateDSN().

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

◆ getDbname()

ilDBPdo::getDbname ( )
Returns
string

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

References $dbname.

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

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

◆ getDBType()

ilDBPdo::getDBType ( )
Returns
string

Implements ilDBInterface.

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

References $db_type.

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

◆ getDBVersion()

ilDBPdo::getDBVersion ( )
Returns
string
Exceptions
ilDatabaseException

Implements ilDBPdoInterface.

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

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

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

References $dsn.

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

979  {
980  return $this->dsn;
981  }
+ Here is the caller graph for this function:

◆ getFieldDefinition()

ilDBPdo::getFieldDefinition ( )
Returns
ilDBPdoFieldDefinition

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

References $field_definition.

Referenced by checkIndexName().

156  {
158  }
+ Here is the caller graph for this function:

◆ getHost()

ilDBPdo::getHost ( )
Returns
string

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

References $host.

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

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

◆ getIndexName()

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

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

References ilDBPdoFieldDefinition\INDEX_FORMAT.

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

◆ getLastErrorCode()

ilDBPdo::getLastErrorCode ( )
Returns
int

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

References $error_code.

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

◆ getLastInsertId()

ilDBPdo::getLastInsertId ( )
Returns
string

Implements ilDBPdoInterface.

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

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

◆ getPassword()

ilDBPdo::getPassword ( )
Returns
string

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

References $password.

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

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

◆ getPort()

ilDBPdo::getPort ( )
Returns
int

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

References $port.

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

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

◆ getPrimaryKeyIdentifier()

ilDBPdo::getPrimaryKeyIdentifier ( )
Returns
string

Implements ilDBInterface.

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

Referenced by addPrimaryKey().

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

◆ getSequenceName()

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

Implements ilDBInterface.

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

References ilDBPdoFieldDefinition\SEQUENCE_FORMAT.

Referenced by ilDBPdoMySQL\nextId().

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

◆ getServerVersion()

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

Implements ilDBPdoInterface.

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

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

◆ getStorageEngine()

ilDBPdo::getStorageEngine ( )
Returns
string

Implements ilDBInterface.

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

References $storage_engine.

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

◆ getUsername()

ilDBPdo::getUsername ( )
Returns
string

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

References $username.

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

1266  {
1267  return $this->username;
1268  }
+ Here is the caller graph for this function:

◆ groupConcat()

ilDBPdo::groupConcat (   $a_field_name,
  $a_seperator = ",",
  $a_order = null 
)

Parameters
string$a_field_name
string$a_seperator
string$a_order
Returns
string

Implements ilDBInterface.

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

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

◆ in()

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

Implements ilDBInterface.

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

References $type.

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

◆ indexExistsByFields()

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

Implements ilDBInterface.

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

References $def, and array.

857  {
858  foreach ($this->manager->listTableIndexes($table_name) as $idx_name) {
859  $def = $this->reverse->getTableIndexDefinition($table_name, $idx_name);
860  $idx_fields = array_keys((array) $def['fields']);
861 
862  if ($idx_fields === $fields) {
863  return true;
864  }
865  }
866 
867  return false;
868  }
Create styles array
The data for the language used.
$def
Definition: croninfo.php:21

◆ initFromIniFile()

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

Implements ilDBInterface.

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

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

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

◆ initHelpers()

ilDBPdo::initHelpers ( )
abstract

Referenced by connect().

+ Here is the caller graph for this function:

◆ initSQLMode()

ilDBPdo::initSQLMode ( )
protected

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

Referenced by connect().

125  {
126  }
+ Here is the caller graph for this function:

◆ insert()

ilDBPdo::insert (   $table_name,
  $values 
)
Parameters
$table_namestring
$values
Returns
int|void

Implements ilDBInterface.

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

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

Referenced by ilDBPdoPostgreSQL\replace().

637  {
638  $real = array();
639  $fields = array();
640  foreach ($values as $key => $val) {
641  $real[] = $this->quote($val[1], $val[0]);
642  $fields[] = $this->quoteIdentifier($key);
643  }
644  $values = implode(",", $real);
645  $fields = implode(",", $fields);
646  $query = "INSERT INTO " . $table_name . " (" . $fields . ") VALUES (" . $values . ")";
647 
649 
650  return $this->pdo->exec($query);
651  }
sanitizeMB4StringIfNotSupported($query)
string to sanitize, all MB4-Characters like emojis will re replaced with ???string sanitized query ...
quote($value, $type=null)
quoteIdentifier($identifier, $check_option=false)
$query
Create styles array
The data for the language used.
$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 931 of file class.ilDBPdo.php.

References fetchAssoc(), and query().

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

References $DIC.

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

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

References $column, and $type.

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

◆ listSequences()

ilDBPdo::listSequences ( )
Returns
array

Implements ilDBInterface.

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

Referenced by sequenceExists().

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

◆ listTables()

ilDBPdo::listTables ( )
Returns
array

Implements ilDBInterface.

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

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

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

◆ loadModule()

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

Implements ilDBInterface.

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

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

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

1500  {
1501  switch ($module) {
1503  return $this->manager;
1505  return $this->reverse;
1506  }
1507  }
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 1573 of file class.ilDBPdo.php.

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

◆ lockTables()

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

Implements ilDBInterface.

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

References $ilLog.

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

◆ lower()

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

Implements ilDBInterface.

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

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

◆ manipulate()

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

Implements ilDBInterface.

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

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

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

762  {
763  global $DIC;
764  $ilBench = $DIC['ilBench'];
765  try {
767  if ($ilBench instanceof ilBenchmark) {
768  $ilBench->startDbBench($query);
769  }
770  $r = $this->pdo->exec($query);
771  if ($ilBench instanceof ilBenchmark) {
772  $ilBench->stopDbBench();
773  }
774  } catch (PDOException $e) {
775  throw new ilDatabaseException($e->getMessage() . ' QUERY: ' . $query);
776  }
777 
778  return $r;
779  }
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 1088 of file class.ilDBPdo.php.

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

Referenced by replace(), and update().

1089  {
1090  if (!is_array($types) || !is_array($values) || count($types) != count($values)) {
1091  throw new ilDatabaseException("ilDB::manipulateF: types and values must be arrays of same size. ($query)");
1092  }
1093  $quoted_values = array();
1094  foreach ($types as $k => $t) {
1095  $quoted_values[] = $this->quote($values[$k], $t);
1096  }
1097  $query = vsprintf($query, $quoted_values);
1098 
1099  return $this->manipulate($query);
1100  }
quote($value, $type=null)
Class ilDatabaseException.
$query
Create styles array
The data for the language used.
manipulate($query)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ migrateAllTablesToCollation()

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

Implements ilDBPdoInterface.

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

References array.

1857  {
1858  return array();
1859  }
Create styles array
The data for the language used.

◆ migrateAllTablesToEngine()

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

Implements ilDBPdoInterface.

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

References array.

1848  {
1849  return array();
1850  }
Create styles array
The data for the language used.

◆ modifyTableColumn()

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

Implements ilDBInterface.

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

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

1587  {
1588  $def = $this->reverse->getTableFieldDefinition($table, $a_column);
1589 
1590  $analyzer = new ilDBAnalyzer($this);
1591  $best_alt = $analyzer->getBestDefinitionAlternative($def);
1592  $def = $def[$best_alt];
1593  unset($def["nativetype"]);
1594  unset($def["mdb2type"]);
1595 
1596  // check attributes
1597  $ilDBPdoFieldDefinition = $this->field_definition;
1598 
1599  $type = ($a_attributes["type"] != "") ? $a_attributes["type"] : $def["type"];
1600  foreach ($def as $k => $v) {
1601  if ($k != "type" && !$ilDBPdoFieldDefinition->isAllowedAttribute($k, $type)) {
1602  unset($def[$k]);
1603  }
1604  }
1605  $check_array = $def;
1606  foreach ($a_attributes as $k => $v) {
1607  $check_array[$k] = $v;
1608  }
1609  if (!$this->checkColumnDefinition($check_array, true)) {
1610  throw new ilDatabaseException("ilDB Error: modifyTableColumn(" . $table . ", " . $a_column . ")");
1611  }
1612 
1613  foreach ($a_attributes as $a => $v) {
1614  $def[$a] = $v;
1615  }
1616 
1617  $a_attributes["definition"] = $def;
1618 
1619  $changes = array(
1620  "change" => array(
1621  $a_column => $a_attributes,
1622  ),
1623  );
1624 
1625  return $this->manager->alterTable($table, $changes, false);
1626  }
$type
Class ilDatabaseException.
Create styles array
The data for the language used.
$def
Definition: croninfo.php:21
if(empty($password)) $table
Definition: pwgen.php:24
This class gives all kind of DB information using the MDB2 manager and reverse module.
checkColumnDefinition($a_def, $a_modify_mode=false)
+ Here is the call graph for this function:

◆ nextId()

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

Implements ilDBInterface.

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

References $rows, array, and tableExists().

252  {
253  $sequence_table_name = $table_name . '_seq';
254 
255  $last_insert_id = $this->pdo->lastInsertId($table_name);
256  if ($last_insert_id) {
257  // return $last_insert_id;
258  }
259 
260  if ($this->tableExists($sequence_table_name)) {
261  $stmt = $this->pdo->prepare("SELECT sequence FROM $sequence_table_name");
262  $stmt->execute();
263  $rows = $stmt->fetch(PDO::FETCH_ASSOC);
264  $stmt->closeCursor();
265  $next_id = $rows['sequence'] + 1;
266  $stmt = $this->pdo->prepare("DELETE FROM $sequence_table_name");
267  $stmt->execute(array("next_id" => $next_id));
268  $stmt = $this->pdo->prepare("INSERT INTO $sequence_table_name (sequence) VALUES (:next_id)");
269  $stmt->execute(array("next_id" => $next_id));
270 
271  return $next_id;
272  }
273 
274  return 1;
275  }
tableExists($table_name)
Create styles array
The data for the language used.
$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 1145 of file class.ilDBPdo.php.

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

◆ numRows()

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

Implements ilDBInterface.

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

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

◆ prepare()

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

Implements ilDBInterface.

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

References $query.

Referenced by autoPrepare().

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

References $query.

Referenced by update().

1395  {
1396  return new ilPDOStatement($this->pdo->prepare($query));
1397  }
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 520 of file class.ilDBPdo.php.

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

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

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

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

Referenced by ilDBPdoMySQL\migrateAllTablesToEngine().

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

◆ queryF()

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

Implements ilDBInterface.

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

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

1067  {
1068  if (!is_array($types) || !is_array($values) || count($types) != count($values)) {
1069  throw new ilDatabaseException("ilDB::queryF: Types and values must be arrays of same size. ($query)");
1070  }
1071  $quoted_values = array();
1072  foreach ($types as $k => $t) {
1073  $quoted_values[] = $this->quote($values[$k], $t);
1074  }
1075  $query = vsprintf($query, $quoted_values);
1076 
1077  return $this->query($query);
1078  }
quote($value, $type=null)
Class ilDatabaseException.
query($query)
$query
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ queryRow()

ilDBPdo::queryRow (   $query,
  $types = null,
  $fetchmode = ilDBConstants::FETCHMODE_DEFAULT 
)
Parameters
$query
null$types
int$fetchmode
Returns
arary

Implements ilDBPdoInterface.

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

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

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

◆ quote()

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

Implements ilDBInterface.

Definition at line 817 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().

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

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

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

References array, and checkTableName().

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

◆ renameTableColumn()

ilDBPdo::renameTableColumn (   $table_name,
  $column_old_name,
  $column_new_name 
)
Parameters
string$table_name
string$column_old_name
string$column_new_name
Returns
bool
Exceptions

Implements ilDBInterface.

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

References $def, array, and checkColumnName().

604  {
605  // check table name
606  if (!$this->checkColumnName($column_new_name)) {
607  throw new ilDatabaseException("ilDB Error: renameTableColumn(" . $table_name . "," . $column_old_name . "," . $column_new_name . ")");
608  }
609 
610  $def = $this->reverse->getTableFieldDefinition($table_name, $column_old_name);
611 
612  $analyzer = new ilDBAnalyzer($this);
613  $best_alt = $analyzer->getBestDefinitionAlternative($def);
614  $def = $def[$best_alt];
615  unset($def["nativetype"]);
616  unset($def["mdb2type"]);
617 
618  $f["definition"] = $def;
619  $f["name"] = $column_new_name;
620 
621  $changes = array(
622  "rename" => array(
623  $column_old_name => $f,
624  ),
625  );
626 
627  return $this->manager->alterTable($table_name, $changes, false);
628  }
Class ilDatabaseException.
checkColumnName($a_name)
Create styles array
The data for the language used.
$def
Definition: croninfo.php:21
This class gives all kind of DB information using the MDB2 manager and reverse module.
+ Here is the call graph for this function:

◆ replace()

ilDBPdo::replace (   $table,
  $primaryKeys,
  $otherColumns 
)

Replace into method.

Parameters
stringtable name
arrayprimary key values: array("field1" => array("text", $name), "field2" => ...)
arrayother values: array("field1" => array("text", $name), "field2" => ...)
Returns
string

Implements ilDBInterface.

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

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

1160  {
1161  $a_columns = array_merge($primaryKeys, $otherColumns);
1162  $fields = array();
1163  $field_values = array();
1164  $placeholders = array();
1165  $types = array();
1166  $values = array();
1167 
1168  foreach ($a_columns as $k => $col) {
1169  $fields[] = $k;
1170  $placeholders[] = "%s";
1171  $placeholders2[] = ":$k";
1172  $types[] = $col[0];
1173 
1174  // integer auto-typecast (this casts bool values to integer)
1175  if ($col[0] == 'integer' && !is_null($col[1])) {
1176  $col[1] = (int) $col[1];
1177  }
1178 
1179  $values[] = $col[1];
1180  $field_values[$k] = $col[1];
1181  }
1182 
1183  $q = "REPLACE INTO " . $table . " (" . implode($fields, ",") . ") VALUES (" . implode($placeholders, ",") . ")";
1184 
1185  $r = $this->manipulateF($q, $types, $values);
1186 
1187  return $r;
1188  }
manipulateF($query, $types, $values)
$r
Definition: example_031.php:79
Create styles array
The data for the language used.
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 1725 of file class.ilDBPdo.php.

References supports().

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

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

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

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

References listSequences().

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

◆ setCharset()

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

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

References $charset.

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

◆ setDBHost()

ilDBPdo::setDBHost (   $host)
Parameters
$host

Implements ilDBInterface.

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

References $host, and setHost().

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

◆ setDbname()

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

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

References $dbname.

Referenced by createDatabase(), and initFromIniFile().

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

◆ setDBPassword()

ilDBPdo::setDBPassword (   $password)
Parameters
$password

Implements ilDBInterface.

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

References $password, and setPassword().

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

◆ setDBPort()

ilDBPdo::setDBPort (   $port)
Parameters
$port

Implements ilDBInterface.

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

References $port, and setPort().

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

◆ setDBType()

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

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

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

Referenced by initFromIniFile().

998  {
999  $this->db_type = $type;
1000  }
$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 1319 of file class.ilDBPdo.php.

References setUsername().

1320  {
1321  $this->setUsername($user);
1322  }
setUsername($username)
+ Here is the call graph for this function:

◆ setFieldDefinition()

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

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

References $field_definition.

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

◆ setHost()

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

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

References $host.

Referenced by initFromIniFile(), and setDBHost().

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

◆ setLimit()

ilDBPdo::setLimit (   $limit,
  $offset = 0 
)

Set the Limit for the next Query.

Parameters
$limit
$offset

Implements ilDBInterface.

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

References $limit, and $offset.

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

◆ setPassword()

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

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

References $password.

Referenced by initFromIniFile(), and setDBPassword().

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

◆ setPort()

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

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

References $port.

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

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

◆ setStorageEngine()

ilDBPdo::setStorageEngine (   $storage_engine)
Parameters
$storage_engine

Implements ilDBInterface.

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

References $storage_engine.

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

◆ setUsername()

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

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

References $username.

Referenced by initFromIniFile(), and setDBUser().

1275  {
1276  $this->username = $username;
1277  }
+ Here is the caller graph for this function:

◆ substr()

ilDBPdo::substr (   $a_exp,
  $a_pos = 1,
  $a_len = -1 
)
Parameters
$a_exp
int$a_pos
int$a_len
Returns
string

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

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

◆ supports()

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

Implements ilDBInterface.

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

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

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

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

1866  {
1867  return false;
1868  }

◆ supportsEngineMigration()

ilDBPdo::supportsEngineMigration ( )
Returns
bool

Implements ilDBPdoInterface.

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

1875  {
1876  return false;
1877  }

◆ supportsFulltext()

ilDBPdo::supportsFulltext ( )
Returns
bool

Implements ilDBInterface.

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

Referenced by addIndex(), and supports().

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

◆ supportsSlave()

ilDBPdo::supportsSlave ( )
Returns
bool

Implements ilDBInterface.

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

Referenced by supports().

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

◆ supportsTransactions()

ilDBPdo::supportsTransactions ( )
Returns
bool

Implements ilDBInterface.

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

Referenced by supports().

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

References loadModule(), and ilDBConstants\MODULE_MANAGER.

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

References $result, and array.

Referenced by nextId().

432  {
433  $result = $this->pdo->prepare("SHOW TABLES LIKE :table_name");
434  $result->execute(array('table_name' => $table_name));
435  $return = $result->rowCount();
436  $result->closeCursor();
437 
438  return $return > 0;
439  }
$result
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ uniqueConstraintExists()

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

Implements ilDBPdoInterface.

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

References $table.

1985  {
1986  require_once('./Services/Database/classes/class.ilDBAnalyzer.php');
1987  $analyzer = new ilDBAnalyzer();
1988  $cons = $analyzer->getConstraintsInformation($table);
1989  foreach ($cons as $c) {
1990  if ($c["type"] == "unique" && count($fields) == count($c["fields"])) {
1991  $all_in = true;
1992  foreach ($fields as $f) {
1993  if (!isset($c["fields"][$f])) {
1994  $all_in = false;
1995  }
1996  }
1997  if ($all_in) {
1998  return true;
1999  }
2000  }
2001  }
2002 
2003  return false;
2004  }
if(empty($password)) $table
Definition: pwgen.php:24
This class gives all kind of DB information using the MDB2 manager and reverse module.

◆ unixTimestamp()

ilDBPdo::unixTimestamp ( )
Returns
string

Implements ilDBPdoInterface.

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

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

◆ unlockTables()

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

Implements ilDBInterface.

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

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

◆ update()

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

Implements ilDBInterface.

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

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

679  {
680  $fields = array();
681  $field_values = array();
682  $placeholders = array();
683  $placeholders_full = array();
684  $types = array();
685  $values = array();
686  $lobs = false;
687  $lob = array();
688  foreach ($columns as $k => $col) {
689  $field_value = $col[1];
690  $fields[] = $k;
691  $placeholders[] = "%s";
692  $placeholders_full[] = ":$k";
693  $types[] = $col[0];
694 
695  if ($col[0] == "blob" || $col[0] == "clob" || $col[0] == 'text') {
696  $field_value = $this->sanitizeMB4StringIfNotSupported($field_value);
697  }
698 
699  // integer auto-typecast (this casts bool values to integer)
700  if ($col[0] == 'integer' && !is_null($field_value)) {
701  $field_value = (int) $field_value;
702  }
703 
704  $values[] = $field_value;
705  $field_values[$k] = $field_value;
706  if ($col[0] == "blob" || $col[0] == "clob") {
707  $lobs = true;
708  $lob[$k] = $k;
709  }
710  }
711 
712  if ($lobs) {
713  $q = "UPDATE " . $table_name . " SET ";
714  $lim = "";
715  foreach ($fields as $k => $field) {
716  $q .= $lim . $field . " = " . $placeholders_full[$k];
717  $lim = ", ";
718  }
719  $q .= " WHERE ";
720  $lim = "";
721  foreach ($where as $k => $col) {
722  $q .= $lim . $k . " = " . $this->quote($col[1], $col[0]);
723  $lim = " AND ";
724  }
725 
726  $r = $this->prepareManip($q, $types);
727  $this->execute($r, $field_values);
728  $this->free($r);
729  } else {
730  foreach ($where as $k => $col) {
731  $types[] = $col[0];
732  $values[] = $col[1];
733  $field_values[$k] = $col;
734  }
735  $q = "UPDATE " . $table_name . " SET ";
736  $lim = "";
737  foreach ($fields as $k => $field) {
738  $q .= $lim . $this->quoteIdentifier($field) . " = " . $placeholders[$k];
739  $lim = ", ";
740  }
741  $q .= " WHERE ";
742  $lim = "";
743  foreach ($where as $k => $col) {
744  $q .= $lim . $k . " = %s";
745  $lim = " AND ";
746  }
747 
748  $r = $this->manipulateF($q, $types, $values);
749  }
750 
751  return $r;
752  }
sanitizeMB4StringIfNotSupported($query)
string to sanitize, all MB4-Characters like emojis will re replaced with ???string sanitized query ...
execute($stmt, $data=array())
quote($value, $type=null)
manipulateF($query, $types, $values)
$r
Definition: example_031.php:79
quoteIdentifier($identifier, $check_option=false)
Create styles array
The data for the language used.
prepareManip($query, $types=null)
if(! $in) $columns
Definition: Utf8Test.php:45
+ Here is the call graph for this function:

◆ upper()

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

Implements ilDBInterface.

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

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

◆ useSlave()

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

TODO

Implements ilDBInterface.

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

1110  {
1111  return false;
1112  }

Field Documentation

◆ $attributes

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

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

Referenced by addTableColumn(), and getAttributes().

◆ $charset

ilDBPdo::$charset = 'utf8'
protected

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

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

◆ $db_type

ilDBPdo::$db_type = ''
protected

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

Referenced by getDBType().

◆ $dbname

ilDBPdo::$dbname = ''
protected

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

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

◆ $dsn

ilDBPdo::$dsn = ''
protected

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

Referenced by getDSN().

◆ $error_code

ilDBPdo::$error_code = 0
protected

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

Referenced by getLastErrorCode().

◆ $field_definition

ilDBPdo::$field_definition
protected

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

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

◆ $host

ilDBPdo::$host = ''
protected

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

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

◆ $limit

ilDBPdo::$limit = null
protected

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

Referenced by appendLimit(), and setLimit().

◆ $manager

ilDBPdo::$manager
protected

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

Referenced by addUniqueConstraint(), and loadModule().

◆ $offset

ilDBPdo::$offset = null
protected

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

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

◆ $password

ilDBPdo::$password = ''
protected

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

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

◆ $pdo

ilDBPdo::$pdo
protected

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

◆ $port

ilDBPdo::$port = 3306
protected

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

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

◆ $reverse

ilDBPdo::$reverse
protected

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

Referenced by loadModule().

◆ $storage_engine

ilDBPdo::$storage_engine = 'MyISAM'
protected

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

Referenced by getStorageEngine(), and setStorageEngine().

◆ $username

ilDBPdo::$username = ''
protected

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

Referenced by getUsername(), and setUsername().

◆ FEATURE_FULLTEXT

const ilDBPdo::FEATURE_FULLTEXT = 'fulltext'

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

◆ FEATURE_SLAVE

const ilDBPdo::FEATURE_SLAVE = 'slave'

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

◆ FEATURE_TRANSACTIONS

const ilDBPdo::FEATURE_TRANSACTIONS = 'transactions'

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


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