27 include_once (
"MDB2.php");
29 define(
"DB_FETCHMODE_ASSOC", MDB2_FETCHMODE_ASSOC);
30 define(
"DB_FETCHMODE_OBJECT", MDB2_FETCHMODE_OBJECT);
86 $parent = get_parent_class($this);
91 $this->setErrorHandling(PEAR_ERROR_CALLBACK, array($this->error_class,
'errorHandler'));
95 $this->raiseError(
"no DSN given", $this->error_class->FATAL);
101 $this->db = MDB2::connect($this->dsn, array(
"use_transactions" =>
true));
108 $cur = ($this->db->getOption(
"portability") & MDB2_PORTABILITY_EMPTY_TO_NULL);
109 $this->db->setOption(
"portability", $this->db->getOption(
"portability") - $cur);
111 $cur = ($this->db->getOption(
"portability") & MDB2_PORTABILITY_FIX_CASE);
112 $this->db->setOption(
"portability", $this->db->getOption(
"portability") - $cur);
116 if (MDB2::isError($this->db)) {
117 $this->raiseError($this->db->getMessage(), $this->error_class->FATAL);
129 $this->
query(
"SET NAMES utf8");
130 $this->
query(
"SET SESSION SQL_MODE = ''");
154 function createTable($a_name, $a_definition_array, $a_options =
"")
156 if ($a_options ==
"")
158 $a_options = array();
161 $manager = $this->db->loadModule(
'Manager');
162 $r = $manager->createTable($a_name, $a_definition_array, $a_options);
164 if (MDB2::isError($r))
167 $this->raiseError($r->getMessage().
"<br><font size=-1>SQL: ".$sql.$err.
"</font>", $this->error_class->FATAL);
190 $r = $this->db->query($sql);
220 if (MDB2::isError($r))
222 $err =
"<br>Details: ".mysql_error();
223 $this->raiseError($r->getMessage().
"<br><font size=-1>SQL: ".$sql.$err.
"</font>", $this->error_class->FATAL);
246 $r = $this->db->exec($sql);
248 if (MDB2::isError($r))
250 $err =
"<br>Details: ".mysql_error();
251 $this->raiseError($r->getMessage().
"<br><font size=-1>SQL: ".$sql.$err.
"</font>", $this->error_class->FATAL);
267 function prepare($a_query, $a_types = null, $a_result_types = null)
269 $res = $this->db->prepare($a_query, $a_types, $a_result_types);
270 if (MDB2::isError(
$res))
272 $this->raiseError(
$res->getMessage().
"<br><font size=-1>SQL: ".$a_query.
"</font>", $this->error_class->FATAL);
290 $res = $this->db->prepare($a_query, $a_types, MDB2_PREPARE_MANIP);
291 if (MDB2::isError(
$res))
293 $this->raiseError(
$res->getMessage().
"<br><font size=-1>SQL: ".$a_query.
"</font>", $this->error_class->FATAL);
311 $res = $a_stmt->execute($a_data);
313 if (MDB2::isError(
$res))
315 $this->raiseError(
$res->getMessage().
"<br><font size=-1>SQL: ".$a_stmt->query .
" with data " . print_r($a_data,
true) .
"</font>", $this->error_class->FATAL);
334 $res = $this->db->extended->executeMultiple($a_stmt,$a_data);
336 if (MDB2::isError(
$res))
338 $this->raiseError(
$res->getMessage().
"<br><font size=-1>SQL: ".
$data.
"</font>", $this->error_class->FATAL);
372 if (count($a_values) == 0)
376 $str = $a_field.
" IN (?".str_repeat(
",?", count($a_values) - 1).
")";
388 $type_arr = array_fill(0, $a_cnt, $a_type);
394 return array_merge($a_arr, $type_arr);
402 return MDB2::isError($a_res);
413 if (!$this->db->supports(
'transactions'))
415 $this->raiseError(
"ilDB::beginTransaction: Transactions are not supported.", $this->error_class->FATAL);
417 $res = $this->db->beginTransaction();
418 if(MDB2::isError(
$res))
420 $this->raiseError(
$res->getMessage().
"<br><font size=-1>SQL: ".$query.
"</font>", $this->error_class->FATAL);
431 $res = $this->db->commit();
432 if(MDB2::isError(
$res))
434 $this->raiseError(
$res->getMessage().
"<br><font size=-1>SQL: ".$query.
"</font>", $this->error_class->FATAL);
445 $res = $this->db->rollback();
446 if(MDB2::isError(
$res))
448 $this->raiseError(
$res->getMessage().
"<br><font size=-1>SQL: ".$query.
"</font>", $this->error_class->FATAL);
459 $res = $this->db->lastInsertId();
460 if(MDB2::isError(
$res))
476 $lock_str =
'LOCK TABLES ';
478 foreach($a_table_params as $table_name => $type)
480 $lock_str .= $counter++ ?
',' :
'';
481 $lock_str .= $table_name.
' '.$type;
484 $ilDB->query($lock_str);
492 $ilDB->query(
'UNLOCK TABLES');
502 return mysql_get_server_info();
511 $version = explode(
".", $this->getMysqlVersion());
512 if((
int) $version[0] >= 4)
524 $version = explode(
".", $this->getMysqlVersion());
525 if ($version[0] ==
"4" && $version[1] ==
"1")
543 $version = explode(
".", $this->getMysqlVersion());
544 if ((
int)$version[0] >= 5 ||
545 ((
int)$version[0] == 4 && (
int)$version[1] >= 1))
562 $this->db->loadModule(
'Extended');
563 define(
'DB_AUTOQUERY_SELECT',MDB2_AUTOQUERY_SELECT);
564 define(
'DB_AUTOQUERY_INSERT',MDB2_AUTOQUERY_INSERT);
565 define(
'DB_AUTOQUERY_UPDATE',MDB2_AUTOQUERY_UPDATE);
566 define(
'DB_AUTOQUERY_DELETE',MDB2_AUTOQUERY_DELETE);
577 if(strlen($a_query) >= $this->max_allowed_packet_size)
601 function autoExecute($a_tablename,$a_fields,$a_mode = MDB2_AUTOQUERY_INSERT,$a_where =
false)
603 $res = $this->db->autoExecute($a_tablename,$a_fields,$a_mode,$a_where);
605 if (MDB2::isError(
$res))
607 $this->raiseError(
$res->getMessage().
"<br><font size=-1>SQL: ".
$data.
"</font>", $this->error_class->FATAL);
622 $query =
"SHOW VARIABLES LIKE 'version'";
623 $res = $this->db->query($query);
624 if(MDB2::isError(
$res))
626 $this->raiseError(
$res->getMessage().
"<br><font size=-1>SQL: ".$query.
"</font>", $this->error_class->FATAL);
630 $version = $row->Value;
634 if(substr($version,0,1) ==
"4")
636 ini_get(
"post_max_size");
637 $query =
"SET GLOBAL max_allowed_packet = ".(int) ini_get(
"post_max_size") * 1024 * 1024;
638 $this->db->query($query);
639 if(MDB2::isError(
$res))
641 $this->raiseError(
$res->getMessage().
"<br><font size=-1>SQL: ".$query.
"</font>", $this->error_class->FATAL);
645 $query =
"SHOW VARIABLES LIKE 'max_allowed_packet'";
646 if(MDB2::isError(
$res))
648 $this->raiseError(
$res->getMessage().
"<br><font size=-1>SQL: ".$query.
"</font>", $this->error_class->FATAL);
650 $res = $this->db->query($query);
654 $this->max_allowed_packet_size = $row->Value;
657 #var_dump("<pre>",$this->max_allowed_packet_size,"<pre>");
672 $column_visibility =
false;
673 $manager = $this->db->loadModule(
'Manager');
674 $r = $manager->listTableFields($a_table);
676 if (!MDB2::isError($r))
678 foreach($r as $field)
680 if ($field == $a_column_name)
682 $column_visibility =
true;
687 return $column_visibility;
710 $manager = $this->db->loadModule(
'Manager');
711 $r = $manager->listTables();
713 if (!MDB2::isError($r))
730 function quote($a_query, $null_as_empty_string =
true)
732 if ($null_as_empty_string)
742 if (method_exists($this->db,
"quoteSmart"))
744 return $this->db->quoteSmart($a_query);
748 return $this->db->quote($a_query);
764 $set = $this->db->query($sql);
766 if (MDB2::isError($set))
768 $this->raiseError($set->getMessage().
"<br><font size=-1>SQL: ".$sql.
"</font>", $this->error_class->FATAL);
789 $set = $this->
query($sql);
790 $r = $set->fetchRow($mode);
793 if (MDB2::isError($r))
795 $this->raiseError($r->getMessage().
"<br><font size=-1>SQL: ".$sql.
"</font>", $this->error_class->FATAL);