ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
ilDBMySQL Class Reference

MySQL Database Wrapper. More...

+ Inheritance diagram for ilDBMySQL:
+ Collaboration diagram for ilDBMySQL:

Public Member Functions

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

Static Public Member Functions

static getReservedWords ()
 Get reserved words. More...
 
- Static Public Member Functions inherited from ilDB
static getReservedWords ()
 Get reserved words. More...
 
static isDbError ($a_res)
 Check error. More...
 
static isReservedWord ($a_word)
 Checks whether a word is a reserved word in one of the supported databases. More...
 

Data Fields

 $max_allowed_packet_size
 
- Data Fields inherited from ilDB
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

 __buildDSN ($a_host, $a_name, $a_user, $a_pass, $a_port="")
 Build DSN string. More...
 
 isMySQLi ()
 
 setMaxAllowedPacket ()
 Set maximum allowed packet size. More...
 
 getCreateTableOptions ()
 
- Protected Member Functions inherited from ilDB
 initConnection ()
 Initialize the database connection. More...
 
 initHostConnection ()
 Initialize the host connection (no specific database) More...
 
 loadMDB2Extensions ()
 load additional mdb2 extensions and set their constants More...
 
 getCreateTableOptions ()
 Get options for the create table statement. More...
 

Protected Attributes

 $slave_active = false
 
 $use_slave = false
 

Detailed Description

MySQL Database Wrapper.

This class extends the main ILIAS database wrapper ilDB. Only a few methods should be overwritten, that contain MySQL specific statements and methods.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
Id
class.ilDB.php 18989 2009-02-15 12:57:19Z akill

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

Member Function Documentation

◆ __buildDSN()

ilDBMySQL::__buildDSN (   $a_host,
  $a_name,
  $a_user,
  $a_pass,
  $a_port = "" 
)
protected

Build DSN string.

Parameters

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

References isMySQLi().

Referenced by getDSN(), and getSlaveDSN().

184  {
185  $db_port_str = "";
186  if (trim($a_port) != "")
187  {
188  $db_port_str = ":".$a_port;
189  }
190 
191  $driver = $this->isMySQLi() ? "mysqli" : "mysql";
192 
193  return $driver."://".$a_user.":".$a_pass.
194  "@".$a_host.$db_port_str."/".$a_name;
195  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addFulltextIndex()

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

Add fulltext index.

Definition at line 505 of file class.ilDBMySQL.php.

References ilDB\constraintName(), and query().

506  {
507  $i_name = $this->constraintName($a_table, $a_name)."_idx";
508  $f_str = implode($a_fields, ",");
509  $q = "ALTER TABLE $a_table ADD FULLTEXT $i_name ($f_str)";
510  $this->query($q);
511  }
query($sql, $a_handle_error=true)
Query.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
+ Here is the call graph for this function:

◆ checkQuerySize()

ilDBMySQL::checkQuerySize (   $a_query)

Check query size.

Definition at line 448 of file class.ilDBMySQL.php.

References $lang.

449  {
450  global $lang;
451 
452  if(strlen($a_query) >= $this->max_allowed_packet_size)
453  {
454  return false;
455  }
456  else
457  {
458  return true;
459  }
460  }

◆ doConnect()

ilDBMySQL::doConnect ( )

Standard way to connect to db.

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

References MDB2\connect(), getDBSlaveActive(), and getSlaveDSN().

312  {
313  parent::doConnect();
314  if ($this->getDBSlaveActive())
315  {
316  $this->slave = MDB2::connect($this->getSlaveDSN(),
317  array("use_transactions" => false));
318  }
319  }
getDBSlaveActive()
Get slave active.
& connect($dsn, $options=false)
Create a new MDB2 connection object and connect to the specified database.
Definition: MDB2.php:431
getSlaveDSN()
Get slave DSN.
+ Here is the call graph for this function:

◆ dropFulltextIndex()

ilDBMySQL::dropFulltextIndex (   $a_table,
  $a_name 
)

Add fulltext index.

Definition at line 516 of file class.ilDBMySQL.php.

References ilDB\constraintName(), and query().

517  {
518  $i_name = $this->constraintName($a_table, $a_name)."_idx";
519  $this->query("ALTER TABLE $a_table DROP FULLTEXT $i_name");
520  }
query($sql, $a_handle_error=true)
Query.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
+ Here is the call graph for this function:

◆ getCreateTableOptions()

ilDBMySQL::getCreateTableOptions ( )
protected

Definition at line 600 of file class.ilDBMySQL.php.

601  {
602  // InnoDB is default engine for MySQL >= 5.5
603  return array('type' => 'MyISAM');
604  }

◆ getDBSlaveActive()

ilDBMySQL::getDBSlaveActive ( )

Get slave active.

Returns
bool slave active

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

References $slave_active.

Referenced by doConnect(), and query().

55  {
56  return $this->slave_active;
57  }
+ Here is the caller graph for this function:

◆ getDBSlaveHost()

ilDBMySQL::getDBSlaveHost ( )

Get slave database host.

Parameters
stringslave database host

Definition at line 114 of file class.ilDBMySQL.php.

Referenced by getSlaveDSN().

115  {
116  return $this->slave_host;
117  }
+ Here is the caller graph for this function:

◆ getDBSlaveName()

ilDBMySQL::getDBSlaveName ( )

Get slave database name.

Parameters
stringslave database name

Definition at line 154 of file class.ilDBMySQL.php.

Referenced by getSlaveDSN().

155  {
156  return $this->slave_name;
157  }
+ Here is the caller graph for this function:

◆ getDBSlavePassword()

ilDBMySQL::getDBSlavePassword ( )

Get slave database password.

Parameters
stringslave database password

Definition at line 134 of file class.ilDBMySQL.php.

Referenced by getSlaveDSN().

135  {
136  return $this->slave_password;
137  }
+ Here is the caller graph for this function:

◆ getDBSlavePort()

ilDBMySQL::getDBSlavePort ( )

Get slave database port.

Parameters
stringslave database port

Definition at line 94 of file class.ilDBMySQL.php.

Referenced by getSlaveDSN().

95  {
96  return $this->slave_port;
97  }
+ Here is the caller graph for this function:

◆ getDBSlaveUser()

ilDBMySQL::getDBSlaveUser ( )

Get slave database user.

Parameters
stringslave database user

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

Referenced by getSlaveDSN().

75  {
76  return $this->slave_user;
77  }
+ Here is the caller graph for this function:

◆ getDBType()

ilDBMySQL::getDBType ( )

Get DB Type.

Definition at line 216 of file class.ilDBMySQL.php.

217  {
218  return "mysql";
219  }

◆ getDBVersion()

ilDBMySQL::getDBVersion ( )

get mysql version

Definition at line 362 of file class.ilDBMySQL.php.

References isMySQLi().

Referenced by isMysql4_0OrHigher(), isMysql4_1(), isMysql4_1OrHigher(), isMysql5_6OrHigher(), and setMaxAllowedPacket().

363  {
364  if(!$this->isMySQLi())
365  {
366  $vers = @mysql_get_server_info();
367  }
368  else
369  {
370  $vers = @mysqli_get_server_info($this->db->connection);
371  }
372  if (trim($vers) == "")
373  {
374  $vers = "Unknown";
375  }
376  return $vers;
377  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDSN()

ilDBMySQL::getDSN ( )

Get DSN.

Definition at line 162 of file class.ilDBMySQL.php.

References __buildDSN(), ilDB\getDBHost(), ilDB\getDBName(), ilDB\getDBPassword(), ilDB\getDBPort(), and ilDB\getDBUser().

163  {
164  return $this->__buildDSN($this->getDBHost(), $this->getDBName(),
165  $this->getDBUser(), $this->getDBPassword(), $this->getDBPort());
166  }
getDBPort()
Get database port.
Definition: class.ilDB.php:113
getDBName()
Get database name.
Definition: class.ilDB.php:173
getDBHost()
Get database host.
Definition: class.ilDB.php:133
getDBUser()
Get database user.
Definition: class.ilDB.php:93
__buildDSN($a_host, $a_name, $a_user, $a_pass, $a_port="")
Build DSN string.
getDBPassword()
Get database password.
Definition: class.ilDB.php:153
+ Here is the call graph for this function:

◆ getErrorNo()

ilDBMySQL::getErrorNo ( )

Definition at line 606 of file class.ilDBMySQL.php.

References isMySQLi().

607  {
608  if(!$this->isMySQLi())
609  {
610  return mysql_errno();
611  }
612  else
613  {
614  return mysqli_errno($this->db->connection);
615  }
616  }
+ Here is the call graph for this function:

◆ getHostDSN()

ilDBMySQL::getHostDSN ( )

Get Host DSN.

Definition at line 205 of file class.ilDBMySQL.php.

References ilDB\getDBPassword(), ilDB\getDBUser(), and isMySQLi().

206  {
207  $driver = $this->isMySQLi() ? "mysqli" : "mysql";
208 
209  return $driver."://".$this->getDBUser().":".$this->getDBPassword().
210  "@".$this->getdbHost();
211  }
getDBUser()
Get database user.
Definition: class.ilDB.php:93
getDBPassword()
Get database password.
Definition: class.ilDB.php:153
+ Here is the call graph for this function:

◆ getLastError()

ilDBMySQL::getLastError ( )

Definition at line 618 of file class.ilDBMySQL.php.

References isMySQLi().

619  {
620  if(!$this->isMySQLi())
621  {
622  return mysql_error();
623  }
624  else
625  {
626  return mysqli_error($this->db->connection);
627  }
628  }
+ Here is the call graph for this function:

◆ getReservedWords()

static ilDBMySQL::getReservedWords ( )
static

Get reserved words.

Definition at line 232 of file class.ilDBMySQL.php.

Referenced by ilDB\isReservedWord().

233  {
234  // version: 5.1
235  // url: http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html
236  return array(
237  "ACCESSIBLE", "ADD", "ALL", "ALTER", "ANALYZE", "AND",
238  "AS", "ASC", "ASENSITIVE", "BEFORE", "BETWEEN", "BIGINT",
239  "BINARY", "BLOB", "BOTH", "BY", "CALL", "CASCADE",
240  "CASE", "CHANGE", "CHAR", "CHARACTER", "CHECK", "COLLATE",
241  "COLUMN", "CONDITION", "CONSTRAINT", "CONTINUE", "CONVERT", "CREATE",
242  "CROSS", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_USER", "CURSOR",
243  "DATABASE", "DATABASES", "DAY_HOUR", "DAY_MICROSECOND", "DAY_MINUTE", "DAY_SECOND",
244  "DEC", "DECIMAL", "DECLARE", "DEFAULT", "DELAYED", "DELETE",
245  "DESC", "DESCRIBE", "DETERMINISTIC", "DISTINCT", "DISTINCTROW", "DIV",
246  "DOUBLE", "DROP", "DUAL", "EACH", "ELSE", "ELSEIF",
247  "ENCLOSED", "ESCAPED", "EXISTS", "EXIT", "EXPLAIN", "FALSE",
248  "FETCH", "FLOAT", "FLOAT4", "FLOAT8", "FOR", "FORCE",
249  "FOREIGN", "FROM", "FULLTEXT", "GRANT", "GROUP", "HAVING",
250  "HIGH_PRIORITY", "HOUR_MICROSECOND", "HOUR_MINUTE", "HOUR_SECOND", "IF", "IGNORE",
251  "IN", "INDEX", "INFILE", "INNER", "INOUT", "INSENSITIVE",
252  "INSERT", "INT", "INT1", "INT2", "INT3", "INT4",
253  "INT8", "INTEGER", "INTERVAL", "INTO", "IS", "ITERATE",
254  "JOIN", "KEY", "KEYS", "KILL", "LEADING", "LEAVE",
255  "LEFT", "LIKE", "LIMIT", "LINEAR", "LINES", "LOAD",
256  "LOCALTIME", "LOCALTIMESTAMP", "LOCK", "LONG", "LONGBLOB", "LONGTEXT",
257  "LOOP", "LOW_PRIORITY", "MASTER_SSL_VERIFY_SERVER_CERT", "MATCH", "MEDIUMBLOB", "MEDIUMINT",
258  "MEDIUMTEXT", "MIDDLEINT", "MINUTE_MICROSECOND", "MINUTE_SECOND", "MOD", "MODIFIES",
259  "NATURAL", "NOT", "NO_WRITE_TO_BINLOG", "NULL", "NUMERIC", "ON",
260  "OPTIMIZE", "OPTION", "OPTIONALLY", "OR", "ORDER", "OUT",
261  "OUTER", "OUTFILE", "PRECISION", "PRIMARY", "PROCEDURE", "PURGE",
262  "RANGE", "READ", "READS", "READ_WRITE", "REAL", "REFERENCES",
263  "REGEXP", "RELEASE", "RENAME", "REPEAT", "REPLACE", "REQUIRE",
264  "RESTRICT", "RETURN", "REVOKE", "RIGHT", "RLIKE", "SCHEMA",
265  "SCHEMAS", "SECOND_MICROSECOND", "SELECT", "SENSITIVE", "SEPARATOR", "SET",
266  "SHOW", "SMALLINT", "SPATIAL", "SPECIFIC", "SQL", "SQLEXCEPTION",
267  "SQLSTATE", "SQLWARNING", "SQL_BIG_RESULT", "SQL_CALC_FOUND_ROWS", "SQL_SMALL_RESULT", "SSL",
268  "STARTING", "STRAIGHT_JOIN", "TABLE", "TERMINATED", "THEN", "TINYBLOB",
269  "TINYINT", "TINYTEXT", "TO", "TRAILING", "TRIGGER", "TRUE",
270  "UNDO", "UNION", "UNIQUE", "UNLOCK", "UNSIGNED", "UPDATE",
271  "USAGE", "USE", "USING", "UTC_DATE", "UTC_TIME", "UTC_TIMESTAMP",
272  "VALUES", "VARBINARY", "VARCHAR", "VARCHARACTER", "VARYING", "WHEN",
273  "WHERE", "WHILE", "WITH", "WRITE", "XOR", "YEAR_MONTH",
274  "ZEROFILL"
275  );
276  }
+ Here is the caller graph for this function:

◆ getSlaveDSN()

ilDBMySQL::getSlaveDSN ( )

Get slave DSN.

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

References __buildDSN(), getDBSlaveHost(), getDBSlaveName(), getDBSlavePassword(), getDBSlavePort(), and getDBSlaveUser().

Referenced by doConnect().

172  {
173  return $this->__buildDSN($this->getDBSlaveHost(), $this->getDBSlaveName(),
174  $this->getDBSlaveUser(), $this->getDBSlavePassword(), $this->getDBSlavePort());
175  }
getDBSlaveHost()
Get slave database host.
getDBSlaveName()
Get slave database name.
getDBSlavePort()
Get slave database port.
getDBSlaveUser()
Get slave database user.
getDBSlavePassword()
Get slave database password.
__buildDSN($a_host, $a_name, $a_user, $a_pass, $a_port="")
Build DSN string.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initConnection()

ilDBMySQL::initConnection ( )

Initialize the database connection.

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

References query(), setMaxAllowedPacket(), and setStorageEngine().

326  {
327  // SET 'max_allowed_packet' (only possible for mysql version 4)
328  $this->setMaxAllowedPacket();
329 
330  // NOTE: Two sourcecodes use this or a similar handling:
331  // - classes/class.ilDB.php
332  // - setup/classes/class.ilClient.php
333 
334  $this->query("SET NAMES utf8");
335  if (DEVMODE == 1)
336  {
337  $this->query("SET SESSION SQL_MODE = 'ONLY_FULL_GROUP_BY'");
338  }
339  $this->setStorageEngine('MYISAM');
340  }
setMaxAllowedPacket()
Set maximum allowed packet size.
query($sql, $a_handle_error=true)
Query.
setStorageEngine($a_storage_engine)
Set the storage engine.
+ Here is the call graph for this function:

◆ initFromIniFile()

ilDBMySQL::initFromIniFile (   $tmpClientIniFile = null)

Init db parameters from ini file.

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

Definition at line 282 of file class.ilDBMySQL.php.

References setDBSlaveActive(), setDBSlaveHost(), setDBSlaveName(), setDBSlavePassword(), setDBSlavePort(), and setDBSlaveUser().

283  {
284  global $ilClientIniFile;
285 
286  parent::initFromIniFile($tmpClientIniFile);
287 
288  //overwrite global client ini file if local parameter is set
289  if (is_object($tmpClientIniFile))
290  $clientIniFile = $tmpClientIniFile;
291  else
292  $clientIniFile = $ilClientIniFile;
293 
294  if (is_object($clientIniFile ))
295  {
296  if ($clientIniFile->readVariable("db", "slave_active") == 1)
297  {
298  $this->setDBSlaveActive(true);
299  $this->setDBSlaveUser($clientIniFile->readVariable("db", "slave_user"));
300  $this->setDBSlaveHost($clientIniFile->readVariable("db", "slave_host"));
301  $this->setDBSlavePort($clientIniFile->readVariable("db", "slave_port"));
302  $this->setDBSlavePassword($clientIniFile->readVariable("db", "slave_pass"));
303  $this->setDBSlaveName($clientIniFile->readVariable("db", "slave_name"));
304  }
305  }
306  }
setDBSlaveUser($a_user)
Set slave database user.
setDBSlaveActive($a_val)
Set slave active.
setDBSlaveHost($a_host)
Set slave database host.
setDBSlavePassword($a_password)
Set slave database password.
setDBSlavePort($a_port)
Set slave database port.
setDBSlaveName($a_name)
Set slave database name.
+ Here is the call graph for this function:

◆ isFulltextIndex()

ilDBMySQL::isFulltextIndex (   $a_table,
  $a_name 
)

Is index a fulltext index?

Definition at line 525 of file class.ilDBMySQL.php.

References ilDB\fetchAssoc(), and query().

526  {
527  $set = $this->query("SHOW INDEX FROM ".$a_table);
528  while ($rec = $this->fetchAssoc($set))
529  {
530  if ($rec["Key_name"] == $a_name && $rec["Index_type"] == "FULLTEXT")
531  {
532  return true;
533  }
534  }
535  }
query($sql, $a_handle_error=true)
Query.
fetchAssoc($a_set)
Fetch row as associative array from result set.
+ Here is the call graph for this function:

◆ isMysql4_0OrHigher()

ilDBMySQL::isMysql4_0OrHigher ( )

check wether current MySQL server is version 4.0.x or higher

Definition at line 383 of file class.ilDBMySQL.php.

References getDBVersion().

384  {
385  $version = explode(".", $this->getDBVersion());
386  if((int) $version[0] < 4)
387  {
388  return false;
389  }
390  return true;
391  }
getDBVersion()
get mysql version
+ Here is the call graph for this function:

◆ isMysql4_1()

ilDBMySQL::isMysql4_1 ( )

check wether current MySQL server is version 4.1.x

Definition at line 396 of file class.ilDBMySQL.php.

References getDBVersion().

397  {
398  $version = explode(".", $this->getDBVersion());
399  if ($version[0] == "4" && $version[1] == "1")
400  {
401  return true;
402  }
403 
404  return false;
405  }
getDBVersion()
get mysql version
+ Here is the call graph for this function:

◆ isMysql4_1OrHigher()

ilDBMySQL::isMysql4_1OrHigher ( )

check wether current MySQL server is version 4.1.x or higher

NOTE: Two sourcecodes use this or a similar handling:

Definition at line 414 of file class.ilDBMySQL.php.

References getDBVersion().

415  {
416  $version = explode(".", $this->getDBVersion());
417  if ((int)$version[0] >= 5 ||
418  ((int)$version[0] == 4 && (int)$version[1] >= 1))
419  {
420  return true;
421  }
422 
423  return false;
424  }
getDBVersion()
get mysql version
+ Here is the call graph for this function:

◆ isMysql5_6OrHigher()

ilDBMySQL::isMysql5_6OrHigher ( )

check wether current MySQL server is version 5.6.x or higher

NOTE: Two sourcecodes use this or a similar handling:

Definition at line 433 of file class.ilDBMySQL.php.

References getDBVersion().

Referenced by setStorageEngine().

434  {
435  $version = explode(".", $this->getDBVersion());
436  if(
437  (int) $version[0] > 5 ||
438  ((int) $version[0] == 5 && (int) $version[1] >= 6))
439  {
440  return true;
441  }
442  return false;
443  }
getDBVersion()
get mysql version
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isMySQLi()

ilDBMySQL::isMySQLi ( )
protected

Definition at line 197 of file class.ilDBMySQL.php.

References ilDB\getSubType().

Referenced by __buildDSN(), getDBVersion(), getErrorNo(), getHostDSN(), and getLastError().

198  {
199  return ($this->getSubType() == "mysqli");
200  }
getSubType()
Get sub type.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lockTables()

ilDBMySQL::lockTables (   $a_tables)

Lock table.

E.g $ilDB->lockTable('tree',ilDB::LOCK_WRITE,'t1')

Parameters
array$a_tables
int$a_mode
string$a_alias
Returns

Definition at line 546 of file class.ilDBMySQL.php.

References $ilLog, ilDB\LOCK_READ, ilDB\LOCK_WRITE, and query().

547  {
548  global $ilLog;
549 
550  $lock = 'LOCK TABLES ';
551 
552  $counter = 0;
553  foreach($a_tables as $table)
554  {
555  if($counter++)
556  {
557  $lock .= ', ';
558  }
559 
560  if( isset($table['sequence']) && $table['sequence'] )
561  {
562  $tableName = $this->db->getSequenceName($table['name']);
563  }
564  else
565  {
566  $tableName = $table['name'];
567  }
568 
569  $lock .= ($tableName.' ');
570 
571  if($table['alias'])
572  {
573  $lock .= ($table['alias'].' ');
574  }
575 
576  switch($table['type'])
577  {
578  case ilDB::LOCK_READ:
579  $lock .= ' READ ';
580  break;
581 
582  case ilDB::LOCK_WRITE:
583  $lock .= ' WRITE ';
584  break;
585  }
586  }
587  $ilLog->write(__METHOD__.': '.$lock);
588  $this->query($lock);
589  }
query($sql, $a_handle_error=true)
Query.
const LOCK_WRITE
Definition: class.ilDB.php:30
const LOCK_READ
Definition: class.ilDB.php:31
+ Here is the call graph for this function:

◆ now()

ilDBMySQL::now ( )

now()

Definition at line 346 of file class.ilDBMySQL.php.

347  {
348  return "now()";
349  }

◆ optimizeTable()

ilDBMySQL::optimizeTable (   $a_table)

Optimize Table.

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

References query().

355  {
356  $this->query("OPTIMIZE TABLE ".$a_table);
357  }
query($sql, $a_handle_error=true)
Query.
+ Here is the call graph for this function:

◆ query()

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

Query.

Parameters

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

References $r, getDBSlaveActive(), and ilDB\handleError().

Referenced by addFulltextIndex(), dropFulltextIndex(), ilDBInnoDB\initConnection(), initConnection(), isFulltextIndex(), lockTables(), optimizeTable(), setMaxAllowedPacket(), setStorageEngine(), and unlockTables().

637  {
638  if (!$this->use_slave || !$this->getDBSlaveActive())
639  {
640  return parent::query($sql, $a_handle_error);
641  }
642 
643  $r = $this->slave->query($sql);
644 
645  if ($a_handle_error)
646  {
647  return $this->handleError($r, "query(".$sql.")");
648  }
649 
650  return $r;
651 
652  }
getDBSlaveActive()
Get slave active.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDBSlaveActive()

ilDBMySQL::setDBSlaveActive (   $a_val)

Set slave active.

Parameters
bool$a_valslave active

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

Referenced by initFromIniFile().

45  {
46  $this->slave_active = $a_val;
47  }
+ Here is the caller graph for this function:

◆ setDBSlaveHost()

ilDBMySQL::setDBSlaveHost (   $a_host)

Set slave database host.

Parameters
stringslave database host

Definition at line 104 of file class.ilDBMySQL.php.

Referenced by initFromIniFile().

105  {
106  $this->slave_host = $a_host;
107  }
+ Here is the caller graph for this function:

◆ setDBSlaveName()

ilDBMySQL::setDBSlaveName (   $a_name)

Set slave database name.

Parameters
stringslave database name

Definition at line 144 of file class.ilDBMySQL.php.

Referenced by initFromIniFile().

145  {
146  $this->slave_name = $a_name;
147  }
+ Here is the caller graph for this function:

◆ setDBSlavePassword()

ilDBMySQL::setDBSlavePassword (   $a_password)

Set slave database password.

Parameters
stringslave database password

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

Referenced by initFromIniFile().

125  {
126  $this->slave_password = $a_password;
127  }
+ Here is the caller graph for this function:

◆ setDBSlavePort()

ilDBMySQL::setDBSlavePort (   $a_port)

Set slave database port.

Parameters
stringslave database port

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

Referenced by initFromIniFile().

85  {
86  $this->slave_port = $a_port;
87  }
+ Here is the caller graph for this function:

◆ setDBSlaveUser()

ilDBMySQL::setDBSlaveUser (   $a_user)

Set slave database user.

Parameters
stringslave database user

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

Referenced by initFromIniFile().

65  {
66  $this->slave_user = $a_user;
67  }
+ Here is the caller graph for this function:

◆ setMaxAllowedPacket()

ilDBMySQL::setMaxAllowedPacket ( )
protected

Set maximum allowed packet size.

todo@: This is MySQL specific and should go to a MySQL specific class.

Definition at line 467 of file class.ilDBMySQL.php.

References $query, $res, $row, DB_FETCHMODE_OBJECT, getDBVersion(), query(), and ilDB\substr().

Referenced by ilDBInnoDB\initConnection(), and initConnection().

468  {
469  $version = $this->getDBVersion();
470 
471  // CHANG VALUE IF MYSQL VERSION > 4.0
472  // Switched back to "SET GLOBAL ..."
473  // @see http://bugs.mysql.com/bug.php?id=22891
474  // smeyer 2009 07 30
475  if (substr($version,0,1) == "4")
476  {
477  ini_get("post_max_size");
478  $query = "SET GLOBAL max_allowed_packet = ".(int) ini_get("post_max_size") * 1024 * 1024;
479 //echo "-".$query."-";
480  $this->query($query);
481  }
482  // STORE NEW max_size in member variable
483  $query = "SHOW VARIABLES LIKE 'max_allowed_packet'";
484  $res = $this->query($query);
485 
486  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
487  {
488  $this->max_allowed_packet_size = $row->value;
489  }
490 //echo "-".$this->max_allowed_packet_size."-";
491  return true;
492  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
query($sql, $a_handle_error=true)
Query.
substr($a_exp, $a_pos=1, $a_len=-1)
Substring.
getDBVersion()
get mysql version
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setStorageEngine()

ilDBMySQL::setStorageEngine (   $a_storage_engine)

Set the storage engine.

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

References isMysql5_6OrHigher(), and query().

Referenced by ilDBInnoDB\initConnection(), and initConnection().

224  {
225  $storage_engine_var = ($this->isMysql5_6OrHigher()) ? "DEFAULT_STORAGE_ENGINE" : "STORAGE_ENGINE";
226  $this->query("SET SESSION " . $storage_engine_var . " = '" . $a_storage_engine . "'");
227  }
query($sql, $a_handle_error=true)
Query.
isMysql5_6OrHigher()
check wether current MySQL server is version 5.6.x or higher
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ supportsFulltext()

ilDBMySQL::supportsFulltext ( )

Is fulltext index supported?

Definition at line 497 of file class.ilDBMySQL.php.

498  {
499  return true;
500  }

◆ supportsSlave()

ilDBMySQL::supportsSlave ( )

Supports slave.

Parameters

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

35  {
36  return true;
37  }

◆ unlockTables()

ilDBMySQL::unlockTables ( )

Unlock tables.

Returns

Definition at line 595 of file class.ilDBMySQL.php.

References query().

596  {
597  $this->query('UNLOCK TABLES');
598  }
query($sql, $a_handle_error=true)
Query.
+ Here is the call graph for this function:

Field Documentation

◆ $max_allowed_packet_size

ilDBMySQL::$max_allowed_packet_size

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

◆ $slave_active

ilDBMySQL::$slave_active = false
protected

Definition at line 25 of file class.ilDBMySQL.php.

Referenced by getDBSlaveActive().

◆ $use_slave

ilDBMySQL::$use_slave = false
protected

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


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