5 include_once(
"./Services/Database/classes/MDB2/class.ilDB.php");
46 $this->slave_active = $a_val;
66 $this->slave_user = $a_user;
76 return $this->slave_user;
86 $this->slave_port = $a_port;
96 return $this->slave_port;
106 $this->slave_host = $a_host;
116 return $this->slave_host;
126 $this->slave_password = $a_password;
136 return $this->slave_password;
146 $this->slave_name = $a_name;
156 return $this->slave_name;
183 protected function __buildDSN($a_host, $a_name, $a_user, $a_pass, $a_port =
"")
186 if (trim($a_port) !=
"")
188 $db_port_str =
":".$a_port;
191 $driver = $this->
isMySQLi() ?
"mysqli" :
"mysql";
193 return $driver.
"://".$a_user.
":".$a_pass.
194 "@".$a_host.$db_port_str.
"/".$a_name;
207 $driver = $this->
isMySQLi() ?
"mysqli" :
"mysql";
210 "@".$this->getdbHost();
225 $storage_engine_var = ($this->
isMysql5_6OrHigher()) ?
"DEFAULT_STORAGE_ENGINE" :
"STORAGE_ENGINE";
226 $this->
query(
"SET SESSION " . $storage_engine_var .
" = '" . $a_storage_engine .
"'");
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",
284 global $ilClientIniFile;
286 parent::initFromIniFile($tmpClientIniFile);
289 if (is_object($tmpClientIniFile))
290 $clientIniFile = $tmpClientIniFile;
292 $clientIniFile = $ilClientIniFile;
294 if (is_object($clientIniFile ))
296 if ($clientIniFile->readVariable(
"db",
"slave_active") == 1)
299 $this->
setDBSlaveUser($clientIniFile->readVariable(
"db",
"slave_user"));
300 $this->
setDBSlaveHost($clientIniFile->readVariable(
"db",
"slave_host"));
301 $this->
setDBSlavePort($clientIniFile->readVariable(
"db",
"slave_port"));
303 $this->
setDBSlaveName($clientIniFile->readVariable(
"db",
"slave_name"));
317 array(
"use_transactions" =>
false));
334 $this->
query(
"SET NAMES utf8");
337 $this->
query(
"SET SESSION SQL_MODE = 'ONLY_FULL_GROUP_BY'");
359 $vers = @mysql_get_server_info();
363 $vers = @mysqli_get_server_info($this->db->connection);
365 if (trim($vers) ==
"")
445 if(strlen($a_query) >= $this->max_allowed_packet_size)
470 ini_get(
"post_max_size");
471 $query =
"SET GLOBAL max_allowed_packet = ".(int) ini_get(
"post_max_size") * 1024 * 1024;
476 $query =
"SHOW VARIABLES LIKE 'max_allowed_packet'";
481 $this->max_allowed_packet_size =
$row->value;
501 $f_str = implode($a_fields,
",");
502 $q =
"ALTER TABLE $a_table ADD FULLTEXT $i_name ($f_str)";
512 $this->
query(
"ALTER TABLE $a_table DROP FULLTEXT $i_name");
520 $set = $this->
query(
"SHOW INDEX FROM ".$a_table);
523 if ($rec[
"Key_name"] == $a_name && $rec[
"Index_type"] ==
"FULLTEXT")
544 $lock =
'LOCK TABLES ';
547 foreach($a_tables as $table)
554 if( isset($table[
'sequence']) && $table[
'sequence'] )
556 $tableName = $this->db->getSequenceName($table[
'name']);
560 $tableName = $table[
'name'];
563 $lock .= ($tableName.
' ');
567 $lock .= ($table[
'alias'].
' ');
570 switch($table[
'type'])
581 if($ilLog instanceof
ilLog) {
582 $ilLog->write(__METHOD__.
': '.$lock);
595 $this->
query(
'UNLOCK TABLES');
601 return array(
'type' =>
'MyISAM');
608 return mysql_errno();
612 return mysqli_errno($this->db->connection);
620 return mysql_error();
624 return mysqli_error($this->db->connection);
632 function query($sql, $a_handle_error =
true)
636 return parent::query($sql, $a_handle_error);
639 $r = $this->slave->query($sql);
656 return $this->db->loadModule($module);
668 public function groupConcat($a_field_name, $a_seperator =
",", $a_order = NULL) {
669 if ($a_order === NULL) {
670 $sql =
"GROUP_CONCAT(" . $a_field_name .
" SEPARATOR " . $this->
quote($a_seperator,
"text") .
")";
672 $sql =
"GROUP_CONCAT(" . $a_field_name .
" ORDER BY " . $a_order .
" SEPARATOR " . $this->
quote($a_seperator,
"text").
")";
setDBSlaveUser($a_user)
Set slave database user.
setDBSlaveActive($a_val)
Set slave active.
getDBSlaveHost()
Get slave database host.
setMaxAllowedPacket()
Set maximum allowed packet size.
getDBSlaveName()
Get slave database name.
getDBSlaveActive()
Get slave active.
isMysql4_0OrHigher()
check wether current MySQL server is version 4.0.x or higher
setDBSlaveHost($a_host)
Set slave database host.
getDBSlavePort()
Get slave database port.
getDBSlaveUser()
Get slave database user.
initConnection()
Initialize the database connection.
getSubType()
Get sub type.
lockTables($a_tables)
Lock table.
supportsSlave()
Supports slave.
initFromIniFile($tmpClientIniFile=null)
Init db parameters from ini file.
setDBSlavePassword($a_password)
Set slave database password.
getDBPort()
Get database port.
getDBSlavePassword()
Get slave database password.
setDBSlavePort($a_port)
Set slave database port.
getHostDSN()
Get Host DSN.
dropFulltextIndex($a_table, $a_name)
Add fulltext index.
getDBName()
Get database name.
query($sql, $a_handle_error=true)
setStorageEngine($a_storage_engine)
Set the storage engine.
fetchAssoc($a_set)
Fetch row as associative array from result set.
quote($a_query, $a_type=null)
Wrapper for quote method.
getDBHost()
Get database host.
setDBSlaveName($a_name)
Set slave database name.
substr($a_exp, $a_pos=1, $a_len=-1)
Substring.
supportsFulltext()
Is fulltext index supported?
getDBUser()
Get database user.
& connect($dsn, $options=false)
Create a new MDB2 connection object and connect to the specified database.
static getReservedWords()
Get reserved words.
__buildDSN($a_host, $a_name, $a_user, $a_pass, $a_port="")
Build DSN string.
doConnect()
Standard way to connect to db.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Create styles array
The data for the language used.
unlockTables()
Unlock tables.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
isFulltextIndex($a_table, $a_name)
Is index a fulltext index?
isMysql4_1OrHigher()
check wether current MySQL server is version 4.1.x or higher
getSlaveDSN()
Get slave DSN.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
getDBPassword()
Get database password.
checkQuerySize($a_query)
Check query size.
addFulltextIndex($a_table, $a_fields, $a_name="in")
Add fulltext index.
isMysql5_6OrHigher()
check wether current MySQL server is version 5.6.x or higher
getDBVersion()
get mysql version
isMysql4_1()
check wether current MySQL server is version 4.1.x
groupConcat($a_field_name, $a_seperator=",", $a_order=NULL)
string