5 include_once (
"./Services/Database/classes/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'");
356 $this->
query(
"OPTIMIZE TABLE ".$a_table);
366 $vers = @mysql_get_server_info();
370 $vers = @mysqli_get_server_info($this->db->connection);
372 if (trim($vers) ==
"")
386 if((
int) $version[0] < 4)
399 if ($version[0] ==
"4" && $version[1] ==
"1")
417 if ((
int)$version[0] >= 5 ||
418 ((
int)$version[0] == 4 && (
int)$version[1] >= 1))
437 (
int) $version[0] > 5 ||
438 ((
int) $version[0] == 5 && (
int) $version[1] >= 6))
452 if(strlen($a_query) >= $this->max_allowed_packet_size)
475 if (
substr($version,0,1) ==
"4")
477 ini_get(
"post_max_size");
478 $query =
"SET GLOBAL max_allowed_packet = ".(int) ini_get(
"post_max_size") * 1024 * 1024;
483 $query =
"SHOW VARIABLES LIKE 'max_allowed_packet'";
488 $this->max_allowed_packet_size =
$row->value;
508 $f_str = implode($a_fields,
",");
509 $q =
"ALTER TABLE $a_table ADD FULLTEXT $i_name ($f_str)";
519 $this->
query(
"ALTER TABLE $a_table DROP FULLTEXT $i_name");
527 $set = $this->
query(
"SHOW INDEX FROM ".$a_table);
530 if ($rec[
"Key_name"] == $a_name && $rec[
"Index_type"] ==
"FULLTEXT")
550 $lock =
'LOCK TABLES ';
553 foreach($a_tables as $table)
560 if( isset($table[
'sequence']) && $table[
'sequence'] )
562 $tableName = $this->db->getSequenceName($table[
'name']);
566 $tableName = $table[
'name'];
569 $lock .= ($tableName.
' ');
573 $lock .= ($table[
'alias'].
' ');
576 switch($table[
'type'])
587 $ilLog->write(__METHOD__.
': '.$lock);
597 $this->
query(
'UNLOCK TABLES');
603 return array(
'type' =>
'MyISAM');
610 return mysql_errno();
614 return mysqli_errno($this->db->connection);
622 return mysql_error();
626 return mysqli_error($this->db->connection);
636 function query($sql, $a_handle_error =
true)
640 return parent::query($sql, $a_handle_error);
643 $r = $this->slave->query($sql);
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.
const DB_FETCHMODE_OBJECT
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)
Query.
setStorageEngine($a_storage_engine)
Set the storage engine.
fetchAssoc($a_set)
Fetch row as associative array from result set.
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.
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.
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
optimizeTable($a_table)
Optimize Table.
isMysql4_1()
check wether current MySQL server is version 4.1.x