ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilDB Class Reference

Database Wrapper. More...

+ Inheritance diagram for ilDB:
+ Collaboration diagram for ilDB:

Public Member Functions

 ilDB ()
 constructor
 setDBUser ($a_user)
 Set database user.
 getDBUser ()
 Get database user.
 setDBPort ($a_port)
 Set database port.
 getDBPort ()
 Get database port.
 setDBHost ($a_host)
 Set database host.
 getDBHost ()
 Get database host.
 setDBPassword ($a_password)
 Set database password.
 getDBPassword ()
 Get database password.
 setDBName ($a_name)
 Set database name.
 getDBName ()
 Get database name.
 getDSN ()
 Get DSN.
 getDBVersion ()
 Get DB version.
 getDBType ()
 Get DSN.
 enableResultBuffering ($a_status)
 En/disable result buffering.
 initFromIniFile ($tmpClientIniFile=null)
 Init db parameters from ini file.
 connect ($a_return_false_for_error=false)
 Open the connection.
 doConnect ()
 Standard way to connect to db.
 disconnect ()
 Disconnect.
 getHostDSN ()
 Should return a valid value, if host connections are possible (connectHost) to create a new database from scratch.
 connectHost ()
 Sets up a host connection only (no specific database used).
 supportsFulltext ()
 supportsSlave ()
 Supports slave.
 useSlave ($a_val=true)
 Use slave.
 handleError ($a_res, $a_info="", $a_level="")
 Handle MDB2 Errors.
 raisePearError ($a_message, $a_level="")
 Raise an error.
 createDatabase ($a_name, $a_charset="utf8", $a_collation="")
 Create database.
 createTable ($a_name, $a_definition_array, $a_drop_table=false, $a_ignore_erros=false)
 Create a new table in the database.
 dropTable ($a_name, $a_error_if_not_existing=true)
 Drop a table.
 alterTable ($a_name, $a_changes)
 Alter a table in the database This method is DEPRECATED, see http://www.ilias.de/docu/goto.php?target=pg_25354_42&client_id=docu PLEASE USE THE SPECIALIZED METHODS OF THIS CLASS TO CHANGE THE DB SCHEMA.
 addTableColumn ($a_table, $a_column, $a_attributes)
 Add table column Use this only on aleady "abstracted" tables.
 dropTableColumn ($a_table, $a_column)
 Drop table column Use this only on aleady "abstracted" tables.
 modifyTableColumn ($a_table, $a_column, $a_attributes)
 Modify a table column Use this only on aleady "abstracted" tables.
 renameTableColumn ($a_table, $a_column, $a_new_column)
 Rename a table column Use this only on aleady "abstracted" tables.
 renameTable ($a_name, $a_new_name)
 Rename a table.
 addPrimaryKey ($a_table, $a_fields)
 Add a primary key to a table.
 getPrimaryKeyIdentifier ()
 Primary key identifier.
 dropPrimaryKey ($a_table)
 Drop a primary key from a table.
 addIndex ($a_table, $a_fields, $a_name="in", $a_fulltext=false)
 Add an index to a table.
 addFulltextIndex ($a_table, $a_fields, $a_name="in")
 Add fulltext index.
 isFulltextIndex ($a_table, $a_name)
 Is index a fulltext index?
 indexExistsByFields ($a_table, $a_fields)
 Check if index exists.
 dropIndexByFields ($a_table, $a_fields)
 Drop index by field(s)
 dropIndex ($a_table, $a_name="in")
 Drop an index from a table.
 addUniqueConstraint ($a_table, $a_fields, $a_name="con")
 Add a unique constraint to a table.
 createSequence ($a_table_name, $a_start=1)
 Create a sequence for a table.
 dropSequence ($a_table_name)
 Drop a sequence for a table.
 checkTableName ($a_name)
 Check whether a table name is valid.
 checkTableColumns ($a_cols)
 Check table columns definition.
 checkColumn ($a_col, $a_def)
 Check column definition.
 checkColumnDefinition ($a_def, $a_modify_mode=false)
 Check whether a column definition is valid.
 checkColumnName ($a_name)
 Check whether a column name is valid.
 checkIndexName ($a_name)
 Check whether an index name is valid.
 getAllowedAttributes ()
 constraintName ($a_table, $a_constraint)
 Determine contraint name by table name and constraint name.
 query ($sql, $a_handle_error=true)
 Query.
 queryF ($a_query, $a_types, $a_values)
 Formatted query (for SELECTS).
 manipulateF ($a_query, $a_types, $a_values)
 Formatted manupulate (for DELETE, UPDATE, INSERT).
 logStatement ($sql)
 Helper function, should usually not be called.
 setLimit ($a_limit, $a_offset=0)
 Set limit and offset for a query.
 nextId ($a_table_name)
 Get next ID for an index.
 manipulate ($sql)
 Data manipulation.
 prepare ($a_query, $a_types=null, $a_result_types=null)
 Prepare a query (SELECT) statement to be used with execute.
 prepareManip ($a_query, $a_types=null)
 Prepare a data manipulation statement to be used with execute.
 execute ($a_stmt, $a_data=null)
 Execute a query statement prepared by either prepare() or prepareManip()
 executeMultiple ($a_stmt, $a_data)
 Execute a query statement prepared by either prepare() or prepareManip() with multiple data arrays.
 insert ($a_table, $a_columns)
 Convenient method for standard insert statements, example field array:
 update ($a_table, $a_columns, $a_where)
 Convenient method for standard update statements, example field array:
 replace ($a_table, $a_pk_columns, $a_other_columns)
 Replace into method.
 fetchAssoc ($a_set)
 Fetch row as associative array from result set.
 free ($a_st)
 Free a statement / result set.
 fetchObject ($a_set)
 Fetch row as object from result set.
 numRows ($a_set)
 Fetch row as associative array from result set.
 in ($a_field, $a_values, $negate=false, $a_type="")
 Get abstract in-clause for given array.
 addTypesToArray ($a_arr, $a_type, $a_cnt)
 Adds a type x times to an array.
 now ()
 now()
 concat ($a_values, $a_allow_null=true)
 Abstraction of SQL function CONCAT.
 substr ($a_exp, $a_pos=1, $a_len=-1)
 Substring.
 upper ($a_exp)
 Upper.
 lower ($a_exp)
 Upper.
 locate ($a_needle, $a_string, $a_start_pos=1)
 Create locate string.
 like ($a_col, $a_type, $a_value="?", $case_insensitive=true)
 Like.
 equals ($a_col, $a_value, $a_type, $a_empty_or_null=false)
 Use this only on text fields.
 equalsNot ($a_col, $a_value, $a_type, $a_empty_or_null=false)
 Use this only on text fields.
 fromUnixtime ($a_expr, $a_to_text=true)
 fromUnixtime (makes timestamp out of unix timestamp)
 unixTimestamp ()
 Unix timestamp.
 optimizeTable ($a_table)
 Optimize Table.
 tableExists ($a_table)
 Check, whether a given table exists.
 tableColumnExists ($a_table, $a_column_name)
 Checks for the existence of a table column.
 uniqueConstraintExists ($a_table, $a_fields)
 Checks if a unique constraint exists based on the fields of the unique constraint (not the name)
 listTables ()
 Get all tables.
 sequenceExists ($a_sequence)
 Check, whether a given sequence exists.
 listSequences ()
 Get all sequences.
 quote ($a_query, $a_type=null)
 Wrapper for quote method.
 quoteIdentifier ($a_identifier)
 Quote table and field names.
 beginTransaction ()
 Begin Transaction.
 commit ()
 Commit a transaction.
 rollback ()
 Rollback a transaction.
 lockTables ($a_tables)
 Abstraction of lock table.
 unlockTables ()
 Unlock tables locked by previous lock table calls.
 autoExecute ($a_tablename, $a_fields, $a_mode=MDB2_AUTOQUERY_INSERT, $a_where=false)
 Wrapper for Pear autoExecute.
 getLastInsertId ()
 Get last insert id.
 getOne ($sql)
 getOne.
 getRow ($sql, $mode=DB_FETCHMODE_OBJECT)
 getRow.
 setSubType ($a_value)
 Set sub type.
 getSubType ()
 Get sub type.
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor.
 _PEAR ()
 Destructor (the emulated type of...).
getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them.
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes.
 isError ($data, $code=null)
 Tell whether a value is a PEAR error.
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled.
 expectError ($code= '*')
 This method is used to tell which errors you expect to get.
 popExpect ()
 This method pops one element off the expected error codes stack.
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available.
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack.
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied.
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options.
 staticPushErrorHandling ($mode, $options=null)
 staticPopErrorHandling ()
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack.
 popErrorHandling ()
 Pop the last error handler used.
 loadExtension ($ext)
 OS independant PHP extension load.

Static Public Member Functions

static getReservedWords ()
 Get reserved words.
static isDbError ($a_res)
 Check error.
static isReservedWord ($a_word)
 Checks whether a word is a reserved word in one of the supported databases.

Data Fields

const LOCK_WRITE = 1
const LOCK_READ = 2
 $error_class
 $db
 $result
 $allowed_attributes
 $sub_type
- Data Fields inherited from PEAR
 $_debug = false
 $_default_error_mode = null
 $_default_error_options = null
 $_default_error_handler = ''
 $_error_class = 'PEAR_Error'
 $_expected_errors = array()

Protected Member Functions

 initConnection ()
 Initialize the database connection.
 initHostConnection ()
 Initialize the host connection (no specific database)
 loadMDB2Extensions ()
 load additional mdb2 extensions and set their constants
 getCreateTableOptions ()
 Get options for the create table statement.

Detailed Description

Database Wrapper.

this class should extend PEAR::DB, add error Management in case of a db-error in any database query the ilDB-class raises an error

Author
Peter Gabriel peter.nosp@m.@gab.nosp@m.riel-.nosp@m.onli.nosp@m.ne.ne.nosp@m.t
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
Id:
class.ilDB.php 54230 2014-10-14 14:51:22Z bheyser

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

Member Function Documentation

ilDB::addFulltextIndex (   $a_table,
  $a_fields,
  $a_name = "in" 
)

Add fulltext index.

Reimplemented in ilDBMySQL.

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

Referenced by addIndex().

{
return false;
}

+ Here is the caller graph for this function:

ilDB::addIndex (   $a_table,
  $a_fields,
  $a_name = "in",
  $a_fulltext = false 
)

Add an index to a table.

Parameters
stringtable name
arrayfields for index
stringindex name

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

References addFulltextIndex(), checkIndexName(), constraintName(), handleError(), raisePearError(), and supportsFulltext().

{
$manager = $this->db->loadModule('Manager');
// check index name
if (!$this->checkIndexName($a_name))
{
$this->raisePearError("ilDB Error: addIndex(".$a_table.",".$a_name.")<br />".
$this->error_str);
}
$fields = array();
foreach ($a_fields as $f)
{
$fields[$f] = array();
}
$definition = array (
'fields' => $fields
);
if (!$a_fulltext)
{
$r = $manager->createIndex($a_table, $this->constraintName($a_table, $a_name), $definition);
}
else
{
if ($this->supportsFulltext())
{
$this->addFulltextIndex($a_table, $a_fields, $a_name);
}
}
return $this->handleError($r, "addIndex(".$a_table.")");
}

+ Here is the call graph for this function:

ilDB::addPrimaryKey (   $a_table,
  $a_fields 
)

Add a primary key to a table.

Parameters
stringtable name
arrayfields for primary key
stringkey name

Definition at line 896 of file class.ilDB.php.

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

{
$manager = $this->db->loadModule('Manager');
$fields = array();
foreach ($a_fields as $f)
{
$fields[$f] = array();
}
$definition = array (
'primary' => true,
'fields' => $fields
);
$r = $manager->createConstraint($a_table,
$this->constraintName($a_table, $this->getPrimaryKeyIdentifier()), $definition);
return $this->handleError($r, "addPrimaryKey(".$a_table.")");
}

+ Here is the call graph for this function:

ilDB::addTableColumn (   $a_table,
  $a_column,
  $a_attributes 
)

Add table column Use this only on aleady "abstracted" tables.

Parameters
stringtable name
stringcolumn name
arrayattributes array("length" => 10, "default" => "t")

Definition at line 675 of file class.ilDB.php.

References checkColumnDefinition(), checkColumnName(), handleError(), and raisePearError().

{
$manager = $this->db->loadModule('Manager');
if (!$this->checkColumnName($a_column))
{
$this->raisePearError("ilDB Error: addTableColumn(".$a_table.", ".$a_column.")<br />".
$this->error_str);
}
if (!$this->checkColumnDefinition($a_attributes))
{
$this->raisePearError("ilDB Error: addTableColumn(".$a_table.", ".$a_column.")<br />".
$this->error_str);
}
$changes = array(
"add" => array(
$a_column => $a_attributes
)
);
$r = $manager->alterTable($a_table, $changes, false);
return $this->handleError($r, "addTableColumn(".$a_table.", ".$a_column.")");
}

+ Here is the call graph for this function:

ilDB::addTypesToArray (   $a_arr,
  $a_type,
  $a_cnt 
)

Adds a type x times to an array.

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

{
if (!is_array($a_arr))
{
$a_arr = array();
}
if ($a_cnt > 0)
{
$type_arr = array_fill(0, $a_cnt, $a_type);
}
else
{
$type_arr = array();
}
return array_merge($a_arr, $type_arr);
}
ilDB::addUniqueConstraint (   $a_table,
  $a_fields,
  $a_name = "con" 
)

Add a unique constraint to a table.

Parameters
stringtable name
arrayfields being unique
stringindex name

Definition at line 1080 of file class.ilDB.php.

References checkIndexName(), constraintName(), handleError(), and raisePearError().

{
$manager = $this->db->loadModule('Manager');
// check index name
if (!$this->checkIndexName($a_name))
{
$this->raisePearError("ilDB Error: addUniqueConstraint(".$a_table.",".$a_name.")<br />".
$this->error_str);
}
$fields = array();
foreach ($a_fields as $f)
{
$fields[$f] = array();
}
$definition = array (
'unique' => true,
'fields' => $fields
);
$r = $manager->createConstraint($a_table, $this->constraintName($a_table, $a_name), $definition);
return $this->handleError($r, "addUniqueConstraint(".$a_table.")");
}

+ Here is the call graph for this function:

ilDB::alterTable (   $a_name,
  $a_changes 
)

Alter a table in the database This method is DEPRECATED, see http://www.ilias.de/docu/goto.php?target=pg_25354_42&client_id=docu PLEASE USE THE SPECIALIZED METHODS OF THIS CLASS TO CHANGE THE DB SCHEMA.

Definition at line 654 of file class.ilDB.php.

References handleError().

{
if ($a_options == "")
{
$a_options = array();
}
$manager = $this->db->loadModule('Manager');
$r = $manager->alterTable($a_name, $a_changes, false);
return $this->handleError($r, "alterTable(".$a_name.")");
}

+ Here is the call graph for this function:

ilDB::autoExecute (   $a_tablename,
  $a_fields,
  $a_mode = MDB2_AUTOQUERY_INSERT,
  $a_where = false 
)

Wrapper for Pear autoExecute.

Parameters
stringtablename
arrayfields values
intMDB2_AUTOQUERY_INSERT or MDB2_AUTOQUERY_UPDATE
stringwhere condition (e.g. "obj_id = '7' AND ref_id = '5'")
Returns
mixed a new DB_result/DB_OK or a DB_Error, if fail

Definition at line 2387 of file class.ilDB.php.

References $res, and handleError().

{
$res = $this->db->autoExecute($a_tablename,$a_fields,$a_mode,$a_where);
return $this->handleError($res, "autoExecute(".$a_tablename.")");
}

+ Here is the call graph for this function:

ilDB::beginTransaction ( )

Begin Transaction.

Please note that we currently do not use savepoints.

Returns
boolean MDB2_OK on success

Definition at line 2328 of file class.ilDB.php.

References $res, handleError(), and raisePearError().

{
if (!$this->db->supports('transactions'))
{
$this->raisePearError("ilDB::beginTransaction: Transactions are not supported.", $this->error_class->FATAL);
}
$res = $this->db->beginTransaction();
return $this->handleError($res, "beginTransaction()");
}

+ Here is the call graph for this function:

ilDB::checkColumn (   $a_col,
  $a_def 
)

Check column definition.

Definition at line 1186 of file class.ilDB.php.

References checkColumnDefinition(), and checkColumnName().

Referenced by checkTableColumns().

{
if (!$this->checkColumnName($a_col))
{
return false;
}
if (!$this->checkColumnDefinition($a_def))
{
return false;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::checkColumnDefinition (   $a_def,
  $a_modify_mode = false 
)

Check whether a column definition is valid.

Parameters
arraydefinition array

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

References $allowed_attributes.

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

{
// check valid type
if (!in_array($a_def["type"], array("text", "integer", "float", "date", "time", "timestamp", "clob", "blob")))
{
switch ($a_def["type"])
{
case "boolean":
$this->error_str = "Invalid column type '".$a_def["type"]."'. Use integer(1) instead.";
break;
case "decimal":
$this->error_str = "Invalid column type '".$a_def["type"]."'. Use float or integer instead.";
break;
default:
$this->error_str = "Invalid column type '".$a_def["type"]."'. Allowed types are: ".
"text, integer, float, date, time, timestamp, clob and blob.";
}
}
// check used attributes
foreach ($a_def as $k => $v)
{
if ($k != "type" && !in_array($k, $allowed_attributes[$a_def["type"]]))
{
$this->error_str = "Attribute '".$k."' is not allowed for column type '".$a_def["type"]."'.";
return false;
}
}
// type specific checks
switch ($a_def["type"])
{
case "text":
if ($a_def["length"] < 1 || $a_def["length"] > 4000)
{
if (!$a_modify_mode || isset($a_def["length"]))
{
$this->error_str = "Invalid length '".$a_def["length"]."' for type text.".
" Length must be >=1 and <= 4000.";
return false;
}
}
break;
case "integer":
if (!in_array($a_def["length"], array(1, 2, 3, 4, 8)))
{
if (!$a_modify_mode || isset($a_def["length"]))
{
$this->error_str = "Invalid length '".$a_def["length"]."' for type integer.".
" Length must be 1, 2, 3, 4 or 8 (bytes).";
return false;
}
}
if ($a_def["unsigned"])
{
$this->error_str = "Unsigned attribut must not be true for type integer.";
return false;
}
break;
}
return true;
}

+ Here is the caller graph for this function:

ilDB::checkColumnName (   $a_name)

Check whether a column name is valid.

Parameters
string$a_name

Definition at line 1280 of file class.ilDB.php.

References isReservedWord(), and substr().

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

{
if (!preg_match ("/^[a-z]+[_a-z0-9]*$/", $a_name))
{
$this->error_str = "Invalid column name '".$a_name."'. Column name must only contain _a-z0-9 and must start with a-z.";
return false;
}
if ($this->isReservedWord($a_name))
{
$this->error_str = "Invalid column name '".$a_name."' (Reserved Word).";
return false;
}
if (strtolower(substr($a_name, 0, 4)) == "sys_")
{
$this->error_str = "Invalid column name '".$a_name."'. Name must not start with 'sys_'.";
return false;
}
if (strlen($a_name) > 30)
{
$this->error_str = "Invalid column name '".$a_name."'. Maximum column identifer lenght is 30 bytes.";
return false;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::checkIndexName (   $a_name)

Check whether an index name is valid.

Parameters
string$a_name

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

References isReservedWord().

Referenced by addIndex(), and addUniqueConstraint().

{
if (!preg_match ("/^[a-z]+[_a-z0-9]*$/", $a_name))
{
$this->error_str = "Invalid column name '".$a_name."'. Column name must only contain _a-z0-9 and must start with a-z.";
return false;
}
if ($this->isReservedWord($a_name))
{
$this->error_str = "Invalid column name '".$a_name."' (Reserved Word).";
return false;
}
if (strlen($a_name) > 3)
{
$this->error_str = "Invalid index name '".$a_name."'. Maximum index identifer lenght is 3 bytes.";
return false;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::checkTableColumns (   $a_cols)

Check table columns definition.

Parameters
arraydefinition array

Definition at line 1170 of file class.ilDB.php.

References checkColumn().

Referenced by createTable().

{
foreach ($a_cols as $col => $def)
{
if (!$this->checkColumn($col, $def))
{
return false;
}
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::checkTableName (   $a_name)

Check whether a table name is valid.

Parameters
string$a_name

Definition at line 1136 of file class.ilDB.php.

References isReservedWord(), and substr().

Referenced by createTable(), and renameTable().

{
if (!preg_match ("/^[a-z]+[_a-z0-9]*$/", $a_name))
{
$this->error_str = "Table name must only contain _a-z0-9 and must start with a-z.";
return false;
}
if ($this->isReservedWord($a_name))
{
$this->error_str = "Invalid table name '".$a_name."' (Reserved Word).";
return false;
}
if (strtolower(substr($a_name, 0, 4)) == "sys_")
{
$this->error_str = "Invalid table name '".$a_name."'. Name must not start with 'sys_'.";
return false;
}
if (strlen($a_name) > 22)
{
$this->error_str = "Invalid table name '".$a_name."'. Maximum table identifer lenght is 22 bytes.";
return false;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::commit ( )

Commit a transaction.

Definition at line 2342 of file class.ilDB.php.

References $res, and handleError().

{
$res = $this->db->commit();
return $this->handleError($res, "commit()");
}

+ Here is the call graph for this function:

ilDB::concat (   $a_values,
  $a_allow_null = true 
)

Abstraction of SQL function CONCAT.

Parameters
array$a_valuesarray( array('title','text'), array('description','clob'), array('some text','text');
bool$a_allow_null
Returns

Reimplemented in ilDBOracle.

Definition at line 1933 of file class.ilDB.php.

{
if(!count($a_values))
{
return ' ';
}
$concat = ' CONCAT(';
$first = true;
foreach($a_values as $field_info)
{
$val = $field_info[0];
if(!$first)
{
$concat .= ',';
}
if($a_allow_null)
{
$concat .= 'COALESCE(';
}
$concat .= $val;
if($a_allow_null)
{
$concat .= ",''";
$concat .= ')';
}
$first = false;
}
$concat .= ') ';
return $concat;
}
ilDB::connect (   $a_return_false_for_error = false)

Open the connection.

Definition at line 241 of file class.ilDB.php.

References doConnect(), getDSN(), handleError(), initConnection(), isDbError(), MDB2\isError(), loadMDB2Extensions(), MDB2_PORTABILITY_ALL, PEAR_ERROR_CALLBACK, raisePearError(), and PEAR\setErrorHandling().

Referenced by connectHost(), ilDBOracle\doConnect(), doConnect(), and ilDBMySQL\doConnect().

{
//set up error handling
$this->error_class = new ilErrorHandling();
$this->setErrorHandling(PEAR_ERROR_CALLBACK, array($this->error_class,'errorHandler'));
//echo $this->getDSN();
//check dsn
if ($this->getDSN() == "")
{
$this->raisePearError("No DSN given");
}
//connect to database
$this->doConnect();
if ($a_return_false_for_error && MDB2::isError($this->db))
{
return false;
}
// set empty value portability to PEAR::DB behaviour
if (!$this->isDbError($this->db))
{
$this->db->setOption('portability', MDB2_PORTABILITY_ALL);
}
//check error
$this->handleError($this->db);
// anything, that must be done to initialize the connection
$this->initConnection();
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::connectHost ( )

Sets up a host connection only (no specific database used).

This is optional during the setup procudure to create databases from scratch.

Definition at line 320 of file class.ilDB.php.

References connect(), getHostDSN(), handleError(), initHostConnection(), isDbError(), MDB2\isError(), loadMDB2Extensions(), MDB2_PORTABILITY_EMPTY_TO_NULL, MDB2_PORTABILITY_FIX_CASE, PEAR_ERROR_CALLBACK, raisePearError(), and PEAR\setErrorHandling().

{
//set up error handling
$this->error_class = new ilErrorHandling();
$this->setErrorHandling(PEAR_ERROR_CALLBACK, array($this->error_class,'errorHandler'));
//check dsn
if ($this->getHostDSN() == "")
{
$this->raisePearError("No Host DSN given");
}
//connect to database
$this->db = MDB2::connect($this->getHostDSN(),
array("use_transactions" => true));
if ($a_return_false_for_error && MDB2::isError($this->db))
{
return false;
}
// set empty value portability to PEAR::DB behaviour
if (!$this->isDbError($this->db))
{
$cur = ($this->db->getOption("portability") & MDB2_PORTABILITY_EMPTY_TO_NULL);
$this->db->setOption("portability", $this->db->getOption("portability") - $cur);
$cur = ($this->db->getOption("portability") & MDB2_PORTABILITY_FIX_CASE);
$this->db->setOption("portability", $this->db->getOption("portability") - $cur);
}
//check error
$this->handleError($this->db);
// anything, that must be done to initialize the connection
return true;
}

+ Here is the call graph for this function:

ilDB::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)

Reimplemented in ilDBOracle, and ilDBPostgreSQL.

Definition at line 1347 of file class.ilDB.php.

Referenced by ilDBMySQL\addFulltextIndex(), addIndex(), addPrimaryKey(), addUniqueConstraint(), ilDBMySQL\dropFulltextIndex(), dropIndex(), and dropPrimaryKey().

{
return $a_constraint;
}

+ Here is the caller graph for this function:

ilDB::createDatabase (   $a_name,
  $a_charset = "utf8",
  $a_collation = "" 
)

Create database.

Definition at line 527 of file class.ilDB.php.

References query().

{
if ($a_collation != "")
{
$sql = "CREATE DATABASE ".$a_name.
" CHARACTER SET ".$a_charset.
" COLLATE ".$a_collation;
}
else
{
$sql = "CREATE DATABASE ".$a_name.
" CHARACTER SET ".$a_charset;
}
return $this->query($sql, false);
}

+ Here is the call graph for this function:

ilDB::createSequence (   $a_table_name,
  $a_start = 1 
)

Create a sequence for a table.

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

References handleError().

{
$manager = $this->db->loadModule('Manager');
$r = $manager->createSequence($a_table_name, $a_start);
return $this->handleError($r, "createSequence(".$a_table_name.")");
}

+ Here is the call graph for this function:

ilDB::createTable (   $a_name,
  $a_definition_array,
  $a_drop_table = false,
  $a_ignore_erros = false 
)

Create a new table in the database.

Parameters
stringtable name
arraydefinition array: array("col1" => array("type" => "text", ...))
booleandrop table automatically, if it already exists

Definition at line 552 of file class.ilDB.php.

References $options, checkTableColumns(), checkTableName(), dropTable(), getCreateTableOptions(), handleError(), and raisePearError().

{
// check table name
if (!$this->checkTableName($a_name) && !$a_ignore_erros)
{
$this->raisePearError("ilDB Error: createTable(".$a_name.")<br />".
$this->error_str);
}
// check definition array
if (!$this->checkTableColumns($a_definition_array) && !$a_ignore_erros)
{
$this->raisePearError("ilDB Error: createTable(".$a_name.")<br />".
$this->error_str);
}
if ($a_drop_table)
{
$this->dropTable($a_name, false);
}
$manager = $this->db->loadModule('Manager');
$r = $manager->createTable($a_name, $a_definition_array, $options);
return $this->handleError($r, "createTable(".$a_name.")");
}

+ Here is the call graph for this function:

ilDB::disconnect ( )

Disconnect.

Definition at line 289 of file class.ilDB.php.

{
$this->db->disconnect();
}
ilDB::doConnect ( )

Standard way to connect to db.

Reimplemented in ilDBMySQL, and ilDBOracle.

Definition at line 280 of file class.ilDB.php.

References connect(), and getDSN().

Referenced by connect().

{
$this->db = MDB2::connect($this->getDSN(),
array("use_transactions" => true));
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::dropIndex (   $a_table,
  $a_name = "in" 
)

Drop an index from a table.

Note: The index must have been created using MDB2

Parameters
stringtable name
stringindex name

Definition at line 1057 of file class.ilDB.php.

References constraintName(), handleError(), and isFulltextIndex().

Referenced by dropIndexByFields().

{
$manager = $this->db->loadModule('Manager');
if (!$this->isFulltextIndex($a_table, $a_name))
{
$r = $manager->dropIndex($a_table, $this->constraintName($a_table, $a_name));
}
else
{
$this->dropFulltextIndex($a_table, $a_name);
}
return $this->handleError($r, "dropIndex(".$a_table.")");
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::dropIndexByFields (   $a_table,
  $a_fields 
)

Drop index by field(s)

Parameters
type$a_table
type$a_fields
Returns
boolean

Definition at line 1029 of file class.ilDB.php.

References dropIndex().

{
$manager = $this->db->loadModule('Manager');
$reverse = $this->db->loadModule('Reverse');
if($manager)
{
foreach($manager->listTableIndexes($a_table) as $idx_name)
{
$def = $reverse->getTableIndexDefinition($a_table,$idx_name);
$idx_fields = array_keys((array) $def['fields']);
if($idx_fields === $a_fields)
{
return $this->dropIndex($a_table, $idx_name);
}
}
}
return false;
}

+ Here is the call graph for this function:

ilDB::dropPrimaryKey (   $a_table)

Drop a primary key from a table.

Parameters
stringtable name
stringkey name

Reimplemented in ilDBOracle.

Definition at line 929 of file class.ilDB.php.

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

{
$manager = $this->db->loadModule('Manager');
$r = $manager->dropConstraint($a_table,
$this->constraintName($a_table, $this->getPrimaryKeyIdentifier()), true);
return $this->handleError($r, "dropPrimaryKey(".$a_table.")");
}

+ Here is the call graph for this function:

ilDB::dropSequence (   $a_table_name)

Drop a sequence for a table.

Definition at line 1122 of file class.ilDB.php.

References handleError().

{
$manager = $this->db->loadModule('Manager');
$r = $manager->dropSequence($a_table_name);
return $this->handleError($r, "dropSequence(".$a_table_name.")");
}

+ Here is the call graph for this function:

ilDB::dropTable (   $a_name,
  $a_error_if_not_existing = true 
)

Drop a table.

Parameters
stringtable name
booleanraise an error, if table not exists

Definition at line 598 of file class.ilDB.php.

References getDBType(), handleError(), listTables(), and substr().

Referenced by createTable().

{
if (!$a_error_if_not_existing)
{
$tables = $this->listTables();
if (!in_array($a_name, $tables))
{
return;
}
}
$manager = $this->db->loadModule('Manager');
if ($this->getDBType() == "oracle")
{
// drop table constraints
$constraints = $manager->listTableConstraints($a_name);
$this->handleError($constraints, "dropTable(".$a_name."), listTableConstraints");
foreach ($constraints as $c)
{
if (substr($c, 0, 4) != "sys_")
{
$r = $manager->dropConstraint($a_name, $c);
$this->handleError($r, "dropTable(".$a_name."), dropConstraint");
}
}
// drop table indexes
$indexes = $manager->listTableIndexes($a_name);
$this->handleError($indexes, "dropTable(".$a_name."), listTableIndexes");
foreach ($indexes as $i)
{
$r = $manager->dropIndex($a_name, $i);
$this->handleError($r, "dropTable(".$a_name."), dropIndex");
}
}
// drop sequence
$seqs = $manager->listSequences();
if (in_array($a_name, $seqs))
{
$r = $manager->dropSequence($a_name);
$this->handleError($r, "dropTable(".$a_name."), dropSequence");
}
// drop table
$r = $manager->dropTable($a_name);
return $this->handleError($r, "dropTable(".$a_name.")");
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::dropTableColumn (   $a_table,
  $a_column 
)

Drop table column Use this only on aleady "abstracted" tables.

Parameters
stringtable name
stringcolumn name

Definition at line 709 of file class.ilDB.php.

References handleError().

{
$manager = $this->db->loadModule('Manager');
$changes = array(
"remove" => array(
$a_column => array()
)
);
$r = $manager->alterTable($a_table, $changes, false);
return $this->handleError($r, "dropTableColumn(".$a_table.", ".$a_column.")");
}

+ Here is the call graph for this function:

ilDB::enableResultBuffering (   $a_status)

En/disable result buffering.

Parameters
bool$a_status

Definition at line 209 of file class.ilDB.php.

{
$this->db->setOption('result_buffering',$a_status);
}
ilDB::equals (   $a_col,
  $a_value,
  $a_type,
  $a_empty_or_null = false 
)

Use this only on text fields.

Definition at line 2068 of file class.ilDB.php.

References quote().

{
if (!$a_empty_or_null || $a_value != "")
{
return $a_col." = ".$this->quote($a_value, $a_type);
}
else
{
return "(".$a_col." = '' OR $a_col IS NULL)";
}
}

+ Here is the call graph for this function:

ilDB::equalsNot (   $a_col,
  $a_value,
  $a_type,
  $a_empty_or_null = false 
)

Use this only on text fields.

Definition at line 2083 of file class.ilDB.php.

References quote().

{
if (!$a_empty_or_null)
{
return $a_col." <> ".$this->quote($a_value, $a_type);
}
if ($a_value != "")
{
return "(".$a_col." <> ".$this->quote($a_value, $a_type). " OR ".
$a_col." IS NULL)";
}
else
{
return "(".$a_col." <> '' AND $a_col IS NOT NULL)";
}
}

+ Here is the call graph for this function:

ilDB::execute (   $a_stmt,
  $a_data = null 
)

Execute a query statement prepared by either prepare() or prepareManip()

Parameters
objectResource handle of the prepared query.
arrayArray of data (to be used for placeholders)
Returns
mixed A result handle or MDB2_OK on success, a MDB2 error on failure

Definition at line 1583 of file class.ilDB.php.

References $res, and handleError().

{
$res = $a_stmt->execute($a_data);
return $this->handleError($res, "execute(".$a_stmt->query.")");
}

+ Here is the call graph for this function:

ilDB::executeMultiple (   $a_stmt,
  $a_data 
)

Execute a query statement prepared by either prepare() or prepareManip() with multiple data arrays.

Parameters
objectResource handle of the prepared query.
arrayArray of array of data (to be used for placeholders)
Returns
mixed A result handle or MDB2_OK on success, a MDB2 error on failure

Definition at line 1599 of file class.ilDB.php.

References $res, and handleError().

{
$res = $this->db->extended->executeMultiple($a_stmt,$a_data);
return $this->handleError($res, "executeMultiple(".$a_stmt->query.")");
}

+ Here is the call graph for this function:

ilDB::fetchAssoc (   $a_set)

Fetch row as associative array from result set.

Parameters
objectresult set

Definition at line 1818 of file class.ilDB.php.

References DB_FETCHMODE_ASSOC.

Referenced by ilObjTestDynamicQuestionSetConfig\getPoolQuestionChangeListener(), ilDBMySQL\isFulltextIndex(), and ilTestArchiver\updateTestArchive().

{
return $a_set->fetchRow(DB_FETCHMODE_ASSOC);
}

+ Here is the caller graph for this function:

ilDB::fetchObject (   $a_set)

Fetch row as object from result set.

Parameters
objectresult set

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

References DB_FETCHMODE_OBJECT.

{
return $a_set->fetchRow(DB_FETCHMODE_OBJECT);
}
ilDB::free (   $a_st)

Free a statement / result set.

Definition at line 1826 of file class.ilDB.php.

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

{
return $a_st->free();
}

+ Here is the caller graph for this function:

ilDB::fromUnixtime (   $a_expr,
  $a_to_text = true 
)

fromUnixtime (makes timestamp out of unix timestamp)

Parameters
stringexpression
booleantypecasting to text y/n

Reimplemented in ilDBOracle.

Definition at line 2106 of file class.ilDB.php.

{
return "FROM_UNIXTIME(".$a_expr.")";
}
ilDB::getAllowedAttributes ( )

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

References $allowed_attributes.

ilDB::getCreateTableOptions ( )
protected

Get options for the create table statement.

Returns
array

Reimplemented in ilDBMySQL, and ilDBInnoDB.

Definition at line 587 of file class.ilDB.php.

Referenced by createTable().

{
return array();
}

+ Here is the caller graph for this function:

ilDB::getDBHost ( )

Get database host.

Parameters
stringdatabase host

Definition at line 133 of file class.ilDB.php.

References $db_host.

Referenced by ilDBPostgreSQL\getDSN(), ilDBOracle\getDSN(), and ilDBMySQL\getDSN().

{
}

+ Here is the caller graph for this function:

ilDB::getDBName ( )

Get database name.

Parameters
stringdatabase name

Definition at line 173 of file class.ilDB.php.

References $db_name.

Referenced by ilDBPostgreSQL\getDSN(), ilDBOracle\getDSN(), and ilDBMySQL\getDSN().

{
}

+ Here is the caller graph for this function:

ilDB::getDBPassword ( )

Get database password.

Parameters
stringdatabase password

Definition at line 153 of file class.ilDB.php.

Referenced by ilDBPostgreSQL\getDSN(), ilDBOracle\getDSN(), ilDBMySQL\getDSN(), and ilDBMySQL\getHostDSN().

{
return $this->db_password;
}

+ Here is the caller graph for this function:

ilDB::getDBPort ( )

Get database port.

Parameters
stringdatabase port

Definition at line 113 of file class.ilDB.php.

Referenced by ilDBOracle\getDSN(), and ilDBMySQL\getDSN().

{
return $this->db_port;
}

+ Here is the caller graph for this function:

ilDB::getDBType ( )
abstract

Get DSN.

This must be overwritten in DBMS specific class.

Reimplemented in ilDBMySQL, ilDBOracle, ilDBPostgreSQL, and ilDBInnoDB.

Referenced by dropTable().

+ Here is the caller graph for this function:

ilDB::getDBUser ( )

Get database user.

Parameters
stringdatabase user

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

References $db_user.

Referenced by ilDBOracle\getDSN(), ilDBMySQL\getDSN(), and ilDBMySQL\getHostDSN().

{
}

+ Here is the caller graph for this function:

ilDB::getDBVersion ( )

Get DB version.

Reimplemented in ilDBMySQL, and ilDBOracle.

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

{
return "Unknown";
}
ilDB::getDSN ( )
abstract

Get DSN.

This must be overwritten in DBMS specific class.

Reimplemented in ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

Referenced by connect(), and doConnect().

+ Here is the caller graph for this function:

ilDB::getHostDSN ( )

Should return a valid value, if host connections are possible (connectHost) to create a new database from scratch.

Returns
string host dsn (similar to dsn WITHOUT a specific database name)

Reimplemented in ilDBMySQL.

Definition at line 311 of file class.ilDB.php.

Referenced by connectHost().

{
return false;
}

+ Here is the caller graph for this function:

ilDB::getLastInsertId ( )

Get last insert id.

Definition at line 2403 of file class.ilDB.php.

References $res, and MDB2\isError().

{
$res = $this->db->lastInsertId();
{
return false;
}
return $res;
}

+ Here is the call graph for this function:

ilDB::getOne (   $sql)

getOne.

DEPRECATED. Should not be used anymore.

this is the wrapper itself. Runs a query and returns the first column of the first row or in case of an error, jump to errorpage

Parameters
string
Returns
object DB

Definition at line 2422 of file class.ilDB.php.

References DB_FETCHMODE_ASSOC, handleError(), and MDB2\isError().

{
//$r = $this->db->getOne($sql);
$set = $this->db->query($sql);
$this->handleError($set, "getOne(".$sql.")");
if (!MDB2::isError($set))
{
$r = $set->fetchRow(DB_FETCHMODE_ASSOC);
return $r[0];
}
}

+ Here is the call graph for this function:

ilDB::getPrimaryKeyIdentifier ( )

Primary key identifier.

Reimplemented in ilDBOracle, and ilDBPostgreSQL.

Definition at line 918 of file class.ilDB.php.

Referenced by addPrimaryKey(), and dropPrimaryKey().

{
return "PRIMARY";
}

+ Here is the caller graph for this function:

static ilDB::getReservedWords ( )
staticabstract

Get reserved words.

This must be overwritten in DBMS specific class. This is mainly used to check whether a new identifier can be problematic because it is a reserved word. So createTable / alterTable usually check these.

Reimplemented in ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

Referenced by isReservedWord().

+ Here is the caller graph for this function:

ilDB::getRow (   $sql,
  $mode = DB_FETCHMODE_OBJECT 
)

getRow.

DEPRECATED. Should not be used anymore

this is the wrapper itself. query a string, and return the resultobject, or in case of an error, jump to errorpage

Parameters
string
Returns
object DB

Definition at line 2446 of file class.ilDB.php.

References handleError(), and query().

{
$set = $this->query($sql);
$r = $set->fetchRow($mode);
//$r = $this->db->getrow($sql,$mode);
$this->handleError($r, "getRow(".$sql.")");
return $r;
} //end function

+ Here is the call graph for this function:

ilDB::getSubType ( )

Get sub type.

Returns
string

Definition at line 2472 of file class.ilDB.php.

References $sub_type.

Referenced by ilDBMySQL\isMySQLi().

{
}

+ Here is the caller graph for this function:

ilDB::handleError (   $a_res,
  $a_info = "",
  $a_level = "" 
)

Handle MDB2 Errors.

Parameters
mixedresult set or anything that is a MDB2::error if something went wrong

Definition at line 405 of file class.ilDB.php.

References $ilLog, MDB2\isError(), and raisePearError().

Referenced by addIndex(), addPrimaryKey(), addTableColumn(), addUniqueConstraint(), alterTable(), autoExecute(), beginTransaction(), commit(), connect(), connectHost(), createSequence(), createTable(), dropIndex(), ilDBOracle\dropPrimaryKey(), dropPrimaryKey(), dropSequence(), dropTable(), dropTableColumn(), execute(), executeMultiple(), getOne(), getRow(), insert(), manipulate(), modifyTableColumn(), nextId(), prepare(), prepareManip(), ilDBMySQL\query(), query(), renameTable(), renameTableColumn(), ilDBPostgreSQL\replace(), ilDBOracle\replace(), replace(), rollback(), and update().

{
global $ilLog;
if (MDB2::isError($a_res))
{
if ($a_level == "")
{
$a_level = $this->error_class->FATAL;
}
// :TODO: ADT (jluetzen)
// if(!$this->exception)
if(true)
{
// Show stack
try
{
throw new Exception();
}
catch(Exception $e)
{
$stack = $e->getTraceAsString();
}
if(is_object($ilLog))
$ilLog->logStack();
$this->raisePearError("ilDB Error: ".$a_info."<br />".
$a_res->getMessage()."<br />".$a_res->getUserInfo()."<br />".$stack, $a_level);
}
/*
else
{
$error = $this->db->errorInfo($a_res->getCode());
$mess = $a_info.
" ### ".$a_res->getMessage().
" ### ".$a_res->getUserInfo();
$exception = new $this->exception($a_res->getUserInfo(), $error[0]);
if($exception instanceof ilADTDBException)
{
// try to find offending column (primary is set AS "PRIMARY")
if($error[0] == MDB2_ERROR_CONSTRAINT && $error[1] == 1062)
{
$col = explode("'", $error[2]);
array_pop($col);
$col = array_pop($col);
$exception->setColumn($col);
}
}
throw $exception;
}
*/
}
/* :TODO: mysql(i) warnings (experimental, jluetzen)
else if(DEVMODE && $this instanceof ilDBMySQL)
{
$j = mysqli_warning_count($this->db->connection);
if($j > 0)
{
$e = mysqli_get_warnings($this->db->connection);
for($i = 0; $i < $j; $i++)
{
trigger_error("MYSQLi warning: "."(".$e->errno.") ".$e->message, E_USER_NOTICE);
$e->next();
}
}
}
*/
return $a_res;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::ilDB ( )

constructor

set up database conncetion and the errorhandling

Parameters
stringdsn database-connection-string for pear-db

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

{
}
ilDB::in (   $a_field,
  $a_values,
  $negate = false,
  $a_type = "" 
)

Get abstract in-clause for given array.

Returns an array "field_name IN (?,?,?,...)" depending on the size of the array

Example: $ids = array(10,12,18); $st = $ilDB->prepare("SELECT * FROM table ". "WHERE ".$ilDB->in("id", $ids), $ilDB->addTypesToArray($types, "integer", count($ids))); $set = $ilDB->execute($st, $ids);

Reimplemented in ilDBOracle.

Definition at line 1866 of file class.ilDB.php.

{
if (count($a_values) == 0)
{
// BEGIN fixed mantis #0014191:
//return " 1=2 "; // return a false statement on empty array
return $negate ? ' 1=1 ' : ' 1=2 ';
// END fixed mantis #0014191:
}
if ($a_type == "") // untyped: used ? for prepare/execute
{
$str = $a_field.(($negate) ? " NOT" : "")." IN (?".str_repeat(",?", count($a_values) - 1).")";
}
else // typed, use values for query/manipulate
{
$str = $a_field.(($negate) ? " NOT" : "")." IN (";
$sep = "";
foreach ($a_values as $v)
{
$str.= $sep.$this->quote($v, $a_type);
$sep = ",";
}
$str.= ")";
}
return $str;
}
ilDB::indexExistsByFields (   $a_table,
  $a_fields 
)

Check if index exists.

Parameters
type$a_table
type$a_fields

Definition at line 1003 of file class.ilDB.php.

{
$manager = $this->db->loadModule('Manager');
$reverse = $this->db->loadModule('Reverse');
if($manager)
{
foreach($manager->listTableIndexes($a_table) as $idx_name)
{
$def = $reverse->getTableIndexDefinition($a_table,$idx_name);
$idx_fields = array_keys((array) $def['fields']);
if($idx_fields === $a_fields)
{
return true;
}
}
}
return false;
}
ilDB::initConnection ( )
protected

Initialize the database connection.

Reimplemented in ilDBMySQL, ilDBOracle, ilDBPostgreSQL, and ilDBInnoDB.

Definition at line 301 of file class.ilDB.php.

Referenced by connect().

{
}

+ Here is the caller graph for this function:

ilDB::initFromIniFile (   $tmpClientIniFile = null)

Init db parameters from ini file.

Parameters
$tmpClientIniFileoverwrite global client ini file if is set to an object

Reimplemented in ilDBMySQL.

Definition at line 218 of file class.ilDB.php.

References setDBHost(), setDBName(), setDBPassword(), setDBPort(), and setDBUser().

{
global $ilClientIniFile;
//overwrite global client ini file if local parameter is set
if (is_object($tmpClientIniFile))
$clientIniFile = $tmpClientIniFile;
else
$clientIniFile = $ilClientIniFile;
if (is_object($clientIniFile ))
{
$this->setDBUser($clientIniFile ->readVariable("db", "user"));
$this->setDBHost($clientIniFile ->readVariable("db", "host"));
$this->setDBPort($clientIniFile ->readVariable("db", "port"));
$this->setDBPassword($clientIniFile ->readVariable("db", "pass"));
$this->setDBName($clientIniFile ->readVariable("db", "name"));
}
}

+ Here is the call graph for this function:

ilDB::initHostConnection ( )
protected

Initialize the host connection (no specific database)

Definition at line 364 of file class.ilDB.php.

Referenced by connectHost().

{
}

+ Here is the caller graph for this function:

ilDB::insert (   $a_table,
  $a_columns 
)

Convenient method for standard insert statements, example field array:

array("field1" => array("text", $name), "field2" => array("integer", $id))

Definition at line 1612 of file class.ilDB.php.

References free(), handleError(), manipulateF(), and MDB2_PREPARE_MANIP.

Referenced by ilDBPostgreSQL\replace(), and ilDBOracle\replace().

{
$fields = array();
$field_values = array();
$placeholders = array();
$types = array();
$values = array();
$lobs = false;
$lob = array();
foreach ($a_columns as $k => $col)
{
$fields[] = $k;
$placeholders[] = "%s";
$placeholders2[] = ":$k";
$types[] = $col[0];
// integer auto-typecast (this casts bool values to integer)
if ($col[0] == 'integer' && !is_null($col[1]))
{
$col[1] = (int) $col[1];
}
$values[] = $col[1];
$field_values[$k] = $col[1];
if ($col[0] == "blob" || $col[0] == "clob")
{
$lobs = true;
$lob[$k] = $k;
}
}
if ($lobs) // lobs -> use prepare execute (autoexecute broken in PEAR 2.4.1)
{
$st = $this->db->prepare("INSERT INTO ".$a_table." (".implode($fields,",").") VALUES (".
implode($placeholders2,",").")", $types, MDB2_PREPARE_MANIP, $lob);
$this->handleError($st, "insert / prepare/execute(".$a_table.")");
$r = $st->execute($field_values);
//$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
$this->handleError($r, "insert / prepare/execute(".$a_table.")");
$this->free($st);
}
else // if no lobs are used, take simple manipulateF
{
$q = "INSERT INTO ".$a_table." (".implode($fields,",").") VALUES (".
implode($placeholders,",").")";
$r = $this->manipulateF($q, $types, $values);
}
return $r;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilDB::isDbError (   $a_res)
static

Check error.

Definition at line 515 of file class.ilDB.php.

References PEAR\isError().

Referenced by connect(), connectHost(), ilNestedSetXML\export(), and loadMDB2Extensions().

{
return MDB2::isError($a_res);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::isFulltextIndex (   $a_table,
  $a_name 
)

Is index a fulltext index?

Reimplemented in ilDBMySQL.

Definition at line 992 of file class.ilDB.php.

Referenced by dropIndex().

{
return false;
}

+ Here is the caller graph for this function:

static ilDB::isReservedWord (   $a_word)
static

Checks whether a word is a reserved word in one of the supported databases.

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

References getReservedWords().

Referenced by checkColumnName(), checkIndexName(), and checkTableName().

{
include_once("./Services/Database/classes/class.ilDBMySQL.php");
$mysql_reserved_words = ilDBMySQL::getReservedWords();
if (in_array(strtoupper($a_word), $mysql_reserved_words))
{
return true;
}
include_once("./Services/Database/classes/class.ilDBOracle.php");
$oracle_reserved_words = ilDBOracle::getReservedWords();
if (in_array(strtoupper($a_word), $oracle_reserved_words))
{
return true;
}
include_once("./Services/Database/classes/class.ilDBPostgreSQL.php");
$postgres_reserved_words = ilDBPostgreSQL::getReservedWords();
if (in_array(strtoupper($a_word), $postgres_reserved_words))
{
return true;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::like (   $a_col,
  $a_type,
  $a_value = "?",
  $case_insensitive = true 
)

Like.

Parameters
stringcolumn type; must be "text" or "clob" ("blob" added for lng_data)

Reimplemented in ilDBOracle.

Definition at line 2032 of file class.ilDB.php.

References quote(), and raisePearError().

{
if (!in_array($a_type, array("text", "clob", "blob")))
{
$this->raisePearError("Like: Invalid column type '".$a_type."'.", $this->error_class->FATAL);
}
if ($a_value == "?")
{
if ($case_insensitive)
{
return "UPPER(".$a_col.") LIKE(UPPER(?))";
}
else
{
return $a_col ." LIKE(?)";
}
}
else
{
if ($case_insensitive)
{
// Always quote as text
return " UPPER(".$a_col.") LIKE(UPPER(".$this->quote($a_value, 'text')."))";
}
else
{
// Always quote as text
return " ".$a_col." LIKE(".$this->quote($a_value, 'text').")";
}
}
}

+ Here is the call graph for this function:

ilDB::listSequences ( )

Get all sequences.

Returns
array Array of sequence names

Definition at line 2264 of file class.ilDB.php.

References MDB2\isError().

Referenced by sequenceExists().

{
$manager = $this->db->loadModule('Manager');
$r = $manager->listSequences();
if (!MDB2::isError($r))
{
return $r;
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::listTables ( )

Get all tables.

Returns
array Array of table names

Definition at line 2226 of file class.ilDB.php.

References MDB2\isError().

Referenced by dropTable(), and tableExists().

{
$manager = $this->db->loadModule('Manager');
$r = $manager->listTables();
if (!MDB2::isError($r))
{
return $r;
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::loadMDB2Extensions ( )
protected

load additional mdb2 extensions and set their constants

protected

Definition at line 500 of file class.ilDB.php.

References isDbError(), MDB2_AUTOQUERY_DELETE, MDB2_AUTOQUERY_INSERT, MDB2_AUTOQUERY_SELECT, and MDB2_AUTOQUERY_UPDATE.

Referenced by connect(), and connectHost().

{
if (!$this->isDbError($this->db))
{
$this->db->loadModule('Extended');
define('DB_AUTOQUERY_SELECT',MDB2_AUTOQUERY_SELECT);
define('DB_AUTOQUERY_INSERT',MDB2_AUTOQUERY_INSERT);
define('DB_AUTOQUERY_UPDATE',MDB2_AUTOQUERY_UPDATE);
define('DB_AUTOQUERY_DELETE',MDB2_AUTOQUERY_DELETE);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::locate (   $a_needle,
  $a_string,
  $a_start_pos = 1 
)

Create locate string.

Parameters
string$a_needle
string$a_string
int$a_start_pos[optional]
Returns

Reimplemented in ilDBOracle.

Definition at line 2014 of file class.ilDB.php.

{
$locate = ' LOCATE( ';
$locate .= $a_needle;
$locate .= ',';
$locate .= $a_string;
$locate .= ',';
$locate .= $a_start_pos;
$locate .= ') ';
return $locate;
}
ilDB::lockTables (   $a_tables)
abstract

Abstraction of lock table.

Parameters
arraytable definitions
Returns

Reimplemented in ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

ilDB::logStatement (   $sql)

Helper function, should usually not be called.

Definition at line 1466 of file class.ilDB.php.

References substr().

{
$pos1 = strpos(strtolower($sql), "from ");
$table = "";
if ($pos1 > 0)
{
$tablef = substr($sql, $pos1+5);
$pos2 = strpos(strtolower($tablef), " ");
if ($pos2 > 0)
{
$table =substr($tablef, 0, $pos2);
}
else
{
$table = $tablef;
}
}
if (trim($table) != "")
{
if (!is_array($this->ttt) || !in_array($table, $this->ttt))
{
echo "<br>".$table;
$this->ttt[] = $table;
}
}
else
{
echo "<br><b>".$sql."</b>";
}
}

+ Here is the call graph for this function:

ilDB::lower (   $a_exp)

Upper.

Parameters
stringexpression
Returns
string upper sql string

Definition at line 2002 of file class.ilDB.php.

{
return " LOWER(".$a_exp.") ";
}
ilDB::manipulate (   $sql)

Data manipulation.

This statement should be used for DELETE, UPDATE and INSERT statements.

Example:

  • "DELETE * FROM data WHERE id =".$ilDB->quote($id, "integer");
Parameters
stringDML string
Returns
int affected rows

Definition at line 1528 of file class.ilDB.php.

References $ilBench, and handleError().

Referenced by manipulateF(), ilDBPostgreSQL\replace(), and ilDBOracle\replace().

{
global $ilBench;
if (is_object($ilBench))
{
$ilBench->startDbBench($sql);
}
$r = $this->db->exec($sql);
if (is_object($ilBench))
{
$ilBench->stopDbBench();
}
return $this->handleError($r, "manipulate(".$sql.")");
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::manipulateF (   $a_query,
  $a_types,
  $a_values 
)

Formatted manupulate (for DELETE, UPDATE, INSERT).

Use s as placeholder!

Parameters
stringquery
arraytype array
arraayvalue array

Definition at line 1446 of file class.ilDB.php.

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

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

{
if (!is_array($a_types) || !is_array($a_values) ||
count($a_types) != count($a_values))
{
$this->raisePearError("ilDB::manipulateF: types and values must be arrays of same size. ($a_query)");
}
$quoted_values = array();
foreach($a_types as $k => $t)
{
$quoted_values[] = $this->quote($a_values[$k], $t);
}
$query = vsprintf($a_query, $quoted_values);
return $this->manipulate($query);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::modifyTableColumn (   $a_table,
  $a_column,
  $a_attributes 
)

Modify a table column Use this only on aleady "abstracted" tables.

Parameters
stringtable name
stringcolumn name
arrayattributes to be changed, e.g. array("length" => 10, "default" => "t")

Definition at line 733 of file class.ilDB.php.

References checkColumnDefinition(), handleError(), and raisePearError().

{
$manager = $this->db->loadModule('Manager');
$reverse = $this->db->loadModule('Reverse');
$def = $reverse->getTableFieldDefinition($a_table, $a_column);
$this->handleError($def, "modifyTableColumn(".$a_table.")");
if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php"))
{
include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
}
else
{
include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
}
$analyzer = new ilDBAnalyzer();
$best_alt = $analyzer->getBestDefinitionAlternative($def);
$def = $def[$best_alt];
unset($def["nativetype"]);
unset($def["mdb2type"]);
// check attributes
$type = ($a_attributes["type"] != "")
? $a_attributes["type"]
: $def["type"];
foreach ($def as $k => $v)
{
if ($k != "type" && !in_array($k, $this->allowed_attributes[$type]))
{
unset($def[$k]);
}
}
$check_array = $def;
foreach ($a_attributes as $k => $v)
{
$check_array[$k] = $v;
}
if (!$this->checkColumnDefinition($check_array, true))
{
$this->raisePearError("ilDB Error: modifyTableColumn(".$a_table.", ".$a_column.")<br />".
$this->error_str);
}
// oracle workaround: do not set null, if null already given
if ($this->getDbType() == "oracle")
{
if ($def["notnull"] == true && ($a_attributes["notnull"] == true
|| !isset($a_attributes["notnull"])))
{
unset($def["notnull"]);
unset($a_attributes["notnull"]);
}
if ($def["notnull"] == false && ($a_attributes["notnull"] == false
|| !isset($a_attributes["notnull"])))
{
unset($def["notnull"]);
unset($a_attributes["notnull"]);
}
}
foreach ($a_attributes as $a => $v)
{
$def[$a] = $v;
}
$a_attributes["definition"] = $def;
$changes = array(
"change" => array(
$a_column => $a_attributes
)
);
$r = $manager->alterTable($a_table, $changes, false);
return $this->handleError($r, "modifyTableColumn(".$a_table.")");
}

+ Here is the call graph for this function:

ilDB::nextId (   $a_table_name)

Get next ID for an index.

Definition at line 1508 of file class.ilDB.php.

References handleError().

{
// we do not create missing sequences automatically here
// otherwise misspelled statements result in additional tables
// please create sequences explicitly in the db update script
$r = $this->db->nextId($a_table_name, false);
return $this->handleError($r, "nextId(".$a_table_name.")");
}

+ Here is the call graph for this function:

ilDB::now ( )

now()

Reimplemented in ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

Definition at line 1918 of file class.ilDB.php.

{
return "now()";
}
ilDB::numRows (   $a_set)

Fetch row as associative array from result set.

Parameters
objectresult set

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

{
return $a_set->numRows();
}
ilDB::optimizeTable (   $a_table)

Optimize Table.

Reimplemented in ilDBMySQL.

Definition at line 2122 of file class.ilDB.php.

{
// needs to be overwritten in DBMS specific class
// if necessary and possible
}
ilDB::prepare (   $a_query,
  $a_types = null,
  $a_result_types = null 
)

Prepare a query (SELECT) statement to be used with execute.

Parameters
StringQuery String
ArrayPlaceholder Types
Returns
Resource handle for the prepared query on success, a MDB2 error on failure.

Definition at line 1553 of file class.ilDB.php.

References $res, and handleError().

{
$res = $this->db->prepare($a_query, $a_types, $a_result_types);
return $this->handleError($res, "prepare(".$a_query.")");
}

+ Here is the call graph for this function:

ilDB::prepareManip (   $a_query,
  $a_types = null 
)

Prepare a data manipulation statement to be used with execute.

Parameters
StringQuery String
ArrayPlaceholder Types
Returns
Resource handle for the prepared query on success, a MDB2 error on failure.

Definition at line 1568 of file class.ilDB.php.

References $res, handleError(), and MDB2_PREPARE_MANIP.

{
$res = $this->db->prepare($a_query, $a_types, MDB2_PREPARE_MANIP);
return $this->handleError($res, "prepareManip(".$a_query.")");
}

+ Here is the call graph for this function:

ilDB::query (   $sql,
  $a_handle_error = true 
)

Query.

Example:

  • "SELECT * FROM data"

For multiple similar queries/manipulations you may use prepare() and execute().

Parameters
string
Returns
object DB

Reimplemented in ilDBMySQL.

Definition at line 1393 of file class.ilDB.php.

References $ilBench, and handleError().

Referenced by ilCourseArchives\__read(), ilRbacSystem\checkAccessOfUser(), createDatabase(), ilRbacReview\getOperation(), ilRbacReview\getOperations(), ilRbacReview\getOperationsOnTypeString(), ilRbacReview\getRoleMailboxAddress(), getRow(), ilDBOracle\initConnection(), ilRbacReview\isDeleted(), ilRbacSystem\preloadRbacPaCache(), queryF(), ilParticipants\readSubscriberData(), ilParticipants\readSubscribers(), ilRbacReview\roleExists(), ilRbacReview\searchRolesByMailboxAddressList(), and ilTestArchiver\updateTestArchive().

{
global $ilBench;
if (is_object($ilBench))
{
$ilBench->startDbBench($sql);
}
$r = $this->db->query($sql);
if (is_object($ilBench))
{
$ilBench->stopDbBench();
}
if ($a_handle_error)
{
return $this->handleError($r, "query(".$sql.")");
}
return $r;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::queryF (   $a_query,
  $a_types,
  $a_values 
)

Formatted query (for SELECTS).

Use s as placeholder!

Parameters
stringquery
arraytype array
arraayvalue array

Definition at line 1422 of file class.ilDB.php.

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

Referenced by ilObjTestDynamicQuestionSetConfig\getPoolQuestionChangeListener().

{
if (!is_array($a_types) || !is_array($a_values) ||
count($a_types) != count($a_values))
{
$this->raisePearError("ilDB::queryF: Types and values must be arrays of same size. ($a_query)");
}
$quoted_values = array();
foreach($a_types as $k => $t)
{
$quoted_values[] = $this->quote($a_values[$k], $t);
}
$query = vsprintf($a_query, $quoted_values);
return $this->query($query);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::quote (   $a_query,
  $a_type = null 
)

Wrapper for quote method.

Definition at line 2285 of file class.ilDB.php.

References raisePearError().

Referenced by equals(), equalsNot(), ilTree\getNodeDataByType(), ilTree\getPathFull(), ilDBOracle\like(), like(), manipulateF(), queryF(), ilDBPostgreSQL\replace(), ilDBOracle\replace(), ilRbacReview\searchRolesByMailboxAddressList(), update(), and ilTestArchiver\updateTestArchive().

{
if ($a_query == "" && is_null($a_type))
{
$a_query = "";
}
// Performance fix
if($a_type == 'integer' && !is_null($a_query))
{
return (int) $a_query;
}
if ($a_type == "blob" || $a_type == "clob")
{
$this->raisePearError("ilDB::quote: Quoting not allowed on type '".$a_type."'. Please use ilDB->insert and ilDB->update to write clobs.", $this->error_class->FATAL);
}
return $this->db->quote($a_query, $a_type);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::quoteIdentifier (   $a_identifier)

Quote table and field names.

Note: IF POSSIBLE, THIS METHOD SHOULD NOT BE USED. Rename your table or field, if it conflicts with a reserved word.

Definition at line 2313 of file class.ilDB.php.

{
return $this->db->quoteIdentifier($a_identifier);
}
ilDB::raisePearError (   $a_message,
  $a_level = "" 
)

Raise an error.

Definition at line 485 of file class.ilDB.php.

References PEAR\raiseError().

Referenced by addIndex(), addTableColumn(), addUniqueConstraint(), beginTransaction(), connect(), connectHost(), createTable(), handleError(), ilDBOracle\like(), like(), manipulateF(), modifyTableColumn(), queryF(), quote(), renameTable(), and renameTableColumn().

{
if ($a_level == "")
{
$a_level = $this->error_class->FATAL;
}
//echo "<br>-ilDB:raising-$a_message-$a_level-";
$this->raiseError($a_message, $a_level);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDB::renameTable (   $a_name,
  $a_new_name 
)

Rename a table.

Parameters
stringold table name
stringnew table name

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

References $query, checkTableName(), handleError(), and raisePearError().

{
// check table name
if (!$this->checkTableName($a_new_name))
{
$this->raisePearError("ilDB Error: renameTable(".$a_name.",".$a_new_name.")<br />".
$this->error_str);
}
$manager = $this->db->loadModule('Manager');
$r = $manager->alterTable($a_name, array("name" => $a_new_name), false);
$query = "UPDATE abstraction_progress ".
"SET table_name = ".$this->db->quote($a_new_name,'text')." ".
"WHERE table_name = ".$this->db->quote($a_name,'text');
$this->db->query($query);
return $this->handleError($r, "renameTable(".$a_name.",".$a_new_name.")");
}

+ Here is the call graph for this function:

ilDB::renameTableColumn (   $a_table,
  $a_column,
  $a_new_column 
)

Rename a table column Use this only on aleady "abstracted" tables.

Parameters
stringtable name
stringold column name
stringnew column name

Definition at line 819 of file class.ilDB.php.

References checkColumnName(), handleError(), and raisePearError().

{
// check table name
if (!$this->checkColumnName($a_new_column))
{
$this->raisePearError("ilDB Error: renameTableColumn(".$a_table.",".$a_column.",".$a_new_column.")<br />".
$this->error_str);
}
$manager = $this->db->loadModule('Manager');
$reverse = $this->db->loadModule('Reverse');
$def = $reverse->getTableFieldDefinition($a_table, $a_column);
$this->handleError($def, "renameTableColumn(".$a_table.",".$a_column.",".$a_new_column.")");
if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php"))
{
include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
}
else
{
include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
}
$analyzer = new ilDBAnalyzer();
$best_alt = $analyzer->getBestDefinitionAlternative($def);
$def = $def[$best_alt];
unset($def["nativetype"]);
unset($def["mdb2type"]);
$f["definition"] = $def;
$f["name"] = $a_new_column;
$changes = array(
"rename" => array(
$a_column => $f
)
);
$r = $manager->alterTable($a_table, $changes, false);
return $this->handleError($r, "renameTableColumn(".$a_table.",".$a_column.",".$a_new_column.")");
}

+ Here is the call graph for this function:

ilDB::replace (   $a_table,
  $a_pk_columns,
  $a_other_columns 
)

Replace into method.

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

Reimplemented in ilDBOracle, and ilDBPostgreSQL.

Definition at line 1762 of file class.ilDB.php.

References free(), handleError(), manipulateF(), and MDB2_PREPARE_MANIP.

{
// this is the mysql implementation
$a_columns = array_merge($a_pk_columns, $a_other_columns);
$fields = array();
$field_values = array();
$placeholders = array();
$types = array();
$values = array();
$lobs = false;
$lob = array();
foreach ($a_columns as $k => $col)
{
$fields[] = $k;
$placeholders[] = "%s";
$placeholders2[] = ":$k";
$types[] = $col[0];
// integer auto-typecast (this casts bool values to integer)
if ($col[0] == 'integer' && !is_null($col[1]))
{
$col[1] = (int) $col[1];
}
$values[] = $col[1];
$field_values[$k] = $col[1];
if ($col[0] == "blob" || $col[0] == "clob")
{
$lobs = true;
$lob[$k] = $k;
}
}
if ($lobs) // lobs -> use prepare execute (autoexecute broken in PEAR 2.4.1)
{
$st = $this->db->prepare("REPLACE INTO ".$a_table." (".implode($fields,",").") VALUES (".
implode($placeholders2,",").")", $types, MDB2_PREPARE_MANIP, $lob);
$this->handleError($st, "insert / prepare/execute(".$a_table.")");
$r = $st->execute($field_values);
//$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
$this->handleError($r, "insert / prepare/execute(".$a_table.")");
$this->free($st);
}
else // if no lobs are used, take simple manipulateF
{
$q = "REPLACE INTO ".$a_table." (".implode($fields,",").") VALUES (".
implode($placeholders,",").")";
$r = $this->manipulateF($q, $types, $values);
}
return $r;
}

+ Here is the call graph for this function:

ilDB::rollback ( )

Rollback a transaction.

Definition at line 2352 of file class.ilDB.php.

References $res, and handleError().

{
$res = $this->db->rollback();
return $this->handleError($res, "rollback()");
}

+ Here is the call graph for this function:

ilDB::sequenceExists (   $a_sequence)

Check, whether a given sequence exists.

Parameters
stringsequence name
Returns
boolean true, if sequence exists

Definition at line 2245 of file class.ilDB.php.

References listSequences().

{
$sequences = $this->listSequences();
if (is_array($sequences))
{
if (in_array($a_sequence, $sequences))
{
return true;
}
}
return false;
}

+ Here is the call graph for this function:

ilDB::setDBHost (   $a_host)

Set database host.

Parameters
stringdatabase host

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

Referenced by initFromIniFile().

{
$this->db_host = $a_host;
}

+ Here is the caller graph for this function:

ilDB::setDBName (   $a_name)

Set database name.

Parameters
stringdatabase name

Definition at line 163 of file class.ilDB.php.

Referenced by initFromIniFile().

{
$this->db_name = $a_name;
}

+ Here is the caller graph for this function:

ilDB::setDBPassword (   $a_password)

Set database password.

Parameters
stringdatabase password

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

Referenced by initFromIniFile().

{
$this->db_password = $a_password;
}

+ Here is the caller graph for this function:

ilDB::setDBPort (   $a_port)

Set database port.

Parameters
stringdatabase port

Definition at line 103 of file class.ilDB.php.

Referenced by initFromIniFile().

{
$this->db_port = $a_port;
}

+ Here is the caller graph for this function:

ilDB::setDBUser (   $a_user)

Set database user.

Parameters
stringdatabase user

Definition at line 83 of file class.ilDB.php.

Referenced by initFromIniFile().

{
$this->db_user = $a_user;
}

+ Here is the caller graph for this function:

ilDB::setLimit (   $a_limit,
  $a_offset = 0 
)

Set limit and offset for a query.

Definition at line 1500 of file class.ilDB.php.

{
$this->db->setLimit($a_limit, $a_offset);
}
ilDB::setSubType (   $a_value)

Set sub type.

Parameters
string$a_value

Definition at line 2462 of file class.ilDB.php.

{
$this->sub_type = (string)$a_value;
}
ilDB::substr (   $a_exp,
  $a_pos = 1,
  $a_len = -1 
)

Substring.

Parameters
@return

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

Referenced by checkColumnName(), checkTableName(), dropTable(), logStatement(), and ilDBMySQL\setMaxAllowedPacket().

{
$lenstr = "";
if ($a_len > -1)
{
$lenstr = ", ".$a_len;
}
return " SUBSTR(".$a_exp.", ".$a_pos.$lenstr.") ";
}

+ Here is the caller graph for this function:

ilDB::supportsFulltext ( )

Reimplemented in ilDBMySQL, ilDBOracle, ilDBPostgreSQL, and ilDBInnoDB.

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

Referenced by addIndex().

{
return false;
}

+ Here is the caller graph for this function:

ilDB::supportsSlave ( )

Supports slave.

Parameters
@return

Reimplemented in ilDBMySQL.

Definition at line 379 of file class.ilDB.php.

Referenced by useSlave().

{
return false;
}

+ Here is the caller graph for this function:

ilDB::tableColumnExists (   $a_table,
  $a_column_name 
)

Checks for the existence of a table column.

Parameters
string$a_tableThe table name which should be examined
string$a_column_nameThe name of the column
Returns
boolean TRUE if the table column exists, FALSE otherwise

Definition at line 2159 of file class.ilDB.php.

References MDB2\isError().

{
$column_visibility = false;
$manager = $this->db->loadModule('Manager');
$r = $manager->listTableFields($a_table);
if (!MDB2::isError($r))
{
foreach($r as $field)
{
if ($field == $a_column_name)
{
$column_visibility = true;
}
}
}
return $column_visibility;
}

+ Here is the call graph for this function:

ilDB::tableExists (   $a_table)

Check, whether a given table exists.

Parameters
stringtable name
Returns
boolean true, if table exists

Definition at line 2138 of file class.ilDB.php.

References listTables().

{
$tables = $this->listTables();
if (is_array($tables))
{
if (in_array($a_table, $tables))
{
return true;
}
}
return false;
}

+ Here is the call graph for this function:

ilDB::uniqueConstraintExists (   $a_table,
  $a_fields 
)

Checks if a unique constraint exists based on the fields of the unique constraint (not the name)

Parameters
string$a_tabletable name
array$a_fieldsarray of field names (strings)
Returns
bool false if no unique constraint with the given fields exists

Definition at line 2187 of file class.ilDB.php.

{
if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php"))
{
include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
}
else
{
include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
}
$analyzer = new ilDBAnalyzer();
$cons = $analyzer->getConstraintsInformation($a_table);
foreach ($cons as $c)
{
if ($c["type"] == "unique" && count($a_fields) == count($c["fields"]))
{
$all_in = true;
foreach ($a_fields as $f)
{
if (!isset($c["fields"][$f]))
{
$all_in = false;
}
}
if ($all_in)
{
return true;
}
}
}
return false;
}
ilDB::unixTimestamp ( )

Unix timestamp.

Reimplemented in ilDBOracle.

Definition at line 2114 of file class.ilDB.php.

{
return "UNIX_TIMESTAMP()";
}
ilDB::unlockTables ( )
abstract

Unlock tables locked by previous lock table calls.

Returns

Reimplemented in ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

ilDB::update (   $a_table,
  $a_columns,
  $a_where 
)

Convenient method for standard update statements, example field array:

array("field1" => array("text", $name), // will use "%s" "field2" => array("integer", $id), // will use "%s"

Example where array: array("id" => array("integer", $id))

Definition at line 1673 of file class.ilDB.php.

References free(), handleError(), manipulateF(), MDB2_PREPARE_MANIP, and quote().

{
$fields = array();
$field_values = array();
$placeholders = array();
$types = array();
$values = array();
$lobs = false;
$lob = array();
foreach ($a_columns as $k => $col)
{
$fields[] = $k;
$placeholders[] = "%s";
$placeholders2[] = ":$k";
$types[] = $col[0];
// integer auto-typecast (this casts bool values to integer)
if ($col[0] == 'integer' && !is_null($col[1]))
{
$col[1] = (int) $col[1];
}
$values[] = $col[1];
$field_values[$k] = $col[1];
if ($col[0] == "blob" || $col[0] == "clob")
{
$lobs = true;
$lob[$k] = $k;
}
}
if ($lobs)
{
$q = "UPDATE ".$a_table." SET ";
$lim = "";
foreach ($fields as $k => $field)
{
$q.= $lim.$field." = ".$placeholders2[$k];
$lim = ", ";
}
$q.= " WHERE ";
$lim = "";
foreach ($a_where as $k => $col)
{
$q.= $lim.$k." = ".$this->quote($col[1], $col[0]);
$lim = " AND ";
}
$st = $this->db->prepare($q, $types, MDB2_PREPARE_MANIP, $lob);
$r = $st->execute($field_values);
//$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
$this->handleError($r, "update / prepare/execute(".$a_table.")");
$this->free($st);
}
else
{
foreach ($a_where as $k => $col)
{
$types[] = $col[0];
$values[] = $col[1];
$field_values[$k] = $col;
}
$q = "UPDATE ".$a_table." SET ";
$lim = "";
foreach ($fields as $k => $field)
{
$q.= $lim.$field." = ".$placeholders[$k];
$lim = ", ";
}
$q.= " WHERE ";
$lim = "";
foreach ($a_where as $k => $col)
{
$q.= $lim.$k." = %s";
$lim = " AND ";
}
$r = $this->manipulateF($q, $types, $values);
}
return $r;
}

+ Here is the call graph for this function:

ilDB::upper (   $a_exp)

Upper.

Parameters
stringexpression
Returns
string upper sql string

Definition at line 1991 of file class.ilDB.php.

{
return " UPPER(".$a_exp.") ";
}
ilDB::useSlave (   $a_val = true)

Use slave.

Parameters
@return

Definition at line 390 of file class.ilDB.php.

References supportsSlave().

{
if (!$this->supportsSlave())
{
return false;
}
$this->use_slave = $a_val;
}

+ Here is the call graph for this function:

Field Documentation

ilDB::$allowed_attributes
Initial value:
array(
"text" => array("length", "notnull", "default", "fixed"),
"integer" => array("length", "notnull", "default", "unsigned"),
"float" => array("notnull", "default"),
"date" => array("notnull", "default"),
"time" => array("notnull", "default"),
"timestamp" => array("notnull", "default"),
"clob" => array("notnull", "default"),
"blob" => array("notnull", "default")
)

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

Referenced by checkColumnDefinition(), and getAllowedAttributes().

ilDB::$db

Definition at line 45 of file class.ilDB.php.

ilDB::$error_class

Definition at line 39 of file class.ilDB.php.

ilDB::$result

Definition at line 51 of file class.ilDB.php.

ilDB::$sub_type

Definition at line 65 of file class.ilDB.php.

Referenced by getSubType().

const ilDB::LOCK_READ = 2

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