Public Member Functions | |
ilDBx ($dsn) | |
constructor | |
_ilDBx () | |
destructor | |
disconnect () | |
disconnect from database | |
query ($sql) | |
query | |
getOne ($sql) | |
getOne | |
quote ($a_query, $null_as_empty_string=true) | |
wrapper for quote method | |
getRow ($sql, $mode=DB_FETCHMODE_OBJECT) | |
getrow | |
getLastInsertId () | |
get last insert id | |
prepare ($query) | |
Wrapper for Pear prepare. | |
executeMultiple ($stmt, $data) | |
Wrapper for Pear executeMultiple. | |
execute ($stmt, $data) | |
Wrapper for Pear executeMultiple. | |
autoExecute ($a_tablename, $a_fields, $a_mode=DB_AUTOQUERY_INSERT, $a_where=false) | |
Wrapper for Pear autoExecute. | |
checkQuerySize ($a_query) | |
setMaxAllowedPacket () | |
_lockTables ($a_table_params) | |
Lock existing table. | |
_unlockTables () | |
getMySQLVersion () | |
get mysql version | |
isMysql4_1 () | |
check wether current MySQL server is version 4.1.x | |
isMysql4_1OrHigher () | |
check wether current MySQL server is version 4.1.x or higher | |
isMysql4_0OrHigher () | |
check wether current MySQL server is version 4.0.x or higher | |
tableColumnExists ($a_table, $a_column_name) | |
Checks for the existence of a table column. | |
Data Fields | |
$error_class | |
$db | |
$result | |
$max_allowed_packet_size |
Definition at line 42 of file class.ilDBx.php.
ilDBx::_ilDBx | ( | ) |
destructor
Definition at line 120 of file class.ilDBx.php.
{ //$this->db->disconnect(); } //end destructor
ilDBx::_lockTables | ( | $ | a_table_params | ) |
Lock existing table.
array | (tablename => lock type READ, WRITE, READ LOCAL or LOW_PRIORITY) e.g array('tree' => 'WRITE') |
Definition at line 369 of file class.ilDBx.php.
References $counter, and $type.
Referenced by ilTree::deleteTree(), ilTree::insertNode(), ilTree::renumber(), and ilTree::saveSubTree().
{ global $ilDB; $lock_str = 'LOCK TABLES '; $counter = 0; foreach($a_table_params as $table_name => $type) { $lock_str .= $counter++ ? ',' : ''; $lock_str .= $table_name.' '.$type; } $ilDB->query($lock_str); return true; }
ilDBx::_unlockTables | ( | ) |
Definition at line 385 of file class.ilDBx.php.
Referenced by ilTree::deleteTree(), ilTree::insertNode(), and ilTree::renumber().
{ global $ilDB; $ilDB->query('UNLOCK TABLES'); return true; }
ilDBx::autoExecute | ( | $ | a_tablename, | |
$ | a_fields, | |||
$ | a_mode = DB_AUTOQUERY_INSERT , |
|||
$ | a_where = false | |||
) |
Wrapper for Pear autoExecute.
string | tablename | |
array | fields values | |
int | DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE | |
string | where condition (e.g. "obj_id = '7' AND ref_id = '5'") |
Definition at line 292 of file class.ilDBx.php.
ilDBx::checkQuerySize | ( | $ | a_query | ) |
Definition at line 305 of file class.ilDBx.php.
References $lang.
{ global $lang; if(strlen($a_query) >= $this->max_allowed_packet_size) { return false; } else { return true; } }
ilDBx::disconnect | ( | ) |
disconnect from database
Definition at line 127 of file class.ilDBx.php.
{
// $this->db->disconnect();
}
ilDBx::execute | ( | $ | stmt, | |
$ | data | |||
) |
Wrapper for Pear executeMultiple.
resource | (statement from prepare) | |
array | multidim array of data |
Definition at line 270 of file class.ilDBx.php.
ilDBx::executeMultiple | ( | $ | stmt, | |
$ | data | |||
) |
Wrapper for Pear executeMultiple.
resource | (statement from prepare) | |
array | multidim array of data |
Definition at line 250 of file class.ilDBx.php.
ilDBx::getLastInsertId | ( | ) |
ilDBx::getMySQLVersion | ( | ) |
get mysql version
Definition at line 397 of file class.ilDBx.php.
{
return mysql_get_server_info();
}
ilDBx::getOne | ( | $ | sql | ) |
getOne
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
string |
Definition at line 166 of file class.ilDBx.php.
{ $r = $this->db->getOne($sql); if (DB::isError($r)) { $this->raiseError($r->getMessage()."<br><font size=-1>SQL: ".$sql."</font>", $this->error_class->FATAL); } else { return $r; } } //end function
ilDBx::getRow | ( | $ | sql, | |
$ | mode = DB_FETCHMODE_OBJECT | |||
) |
getrow
this is the wrapper itself. query a string, and return the resultobject, or in case of an error, jump to errorpage
string |
Definition at line 208 of file class.ilDBx.php.
{ $r = $this->db->getrow($sql,$mode); if (DB::isError($r)) { $this->raiseError($r->getMessage()."<br><font size=-1>SQL: ".$sql."</font>", $this->error_class->FATAL); } else { return $r; } } //end function
ilDBx::ilDBx | ( | $ | dsn | ) |
constructor
set up database conncetion and the errorhandling
string | dsn database-connection-string for pear-db |
Definition at line 77 of file class.ilDBx.php.
References isMysql4_1OrHigher(), query(), and setMaxAllowedPacket().
{ //call parent constructor $parent = get_parent_class($this); $this->$parent(); //set up error handling $this->error_class = new ilErrorHandling(); $this->setErrorHandling(PEAR_ERROR_CALLBACK, array($this->error_class,'errorHandler')); //check dsn if ($dsn=="") $this->raiseError("no DSN given", $this->error_class->FATAL); $this->dsn = $dsn; //connect to database $this->db = DB::connect($this->dsn, true); //check error if (DB::isError($this->db)) { $this->raiseError($this->db->getMessage(), $this->error_class->FATAL); } // SET 'max_allowed_packet' (only possible for mysql version 4) $this->setMaxAllowedPacket(); // NOTE: Three sourcecodes use this or a similar handling: // - classes/class.ilDBx.php // - calendar/classes/class.ilCalInterface.php->setNames // - setup/classes/class.ilClient.php if ($this->isMysql4_1OrHigher()) { $this->query("SET NAMES utf8"); $this->query("SET SESSION SQL_MODE = ''"); } return true; } //end constructor
ilDBx::isMysql4_0OrHigher | ( | ) |
check wether current MySQL server is version 4.0.x or higher
Definition at line 439 of file class.ilDBx.php.
{ $version = explode(".", $this->getMysqlVersion()); if((int) $version[0] >= 4) { return true; } return false; }
ilDBx::isMysql4_1 | ( | ) |
check wether current MySQL server is version 4.1.x
Definition at line 405 of file class.ilDBx.php.
{ $version = explode(".", $this->getMysqlVersion()); if ($version[0] == "4" && $version[1] == "1") { return true; } return false; }
ilDBx::isMysql4_1OrHigher | ( | ) |
check wether current MySQL server is version 4.1.x or higher
NOTE: Three sourcecodes use this or a similar handling:
Definition at line 424 of file class.ilDBx.php.
Referenced by ilDBx().
{ $version = explode(".", $this->getMysqlVersion()); if ((int)$version[0] >= 5 || ((int)$version[0] == 4 && (int)$version[1] >= 1)) { return true; } return false; }
ilDBx::prepare | ( | $ | query | ) |
Wrapper for Pear prepare.
String | query |
Definition at line 239 of file class.ilDBx.php.
References $query.
{ return $this->db->prepare($query); }
ilDBx::query | ( | $ | sql | ) |
query
this is the wrapper itself. query a string, and return the resultobject, or in case of an error, jump to errorpage
string |
Definition at line 141 of file class.ilDBx.php.
Referenced by getLastInsertId(), and ilDBx().
{ $r = $this->db->query($sql); if (DB::isError($r)) { $err = "<br>Details: ".mysql_error(); $this->raiseError($r->getMessage()."<br><font size=-1>SQL: ".$sql.$err."</font>", $this->error_class->FATAL); } else { return $r; } } //end function
ilDBx::quote | ( | $ | a_query, | |
$ | null_as_empty_string = true | |||
) |
wrapper for quote method
Definition at line 184 of file class.ilDBx.php.
{ if ($null_as_empty_string) { if ($a_query == "") { $a_query = ""; } } // maybe quoteSmart should be used in the future return $this->db->quote($a_query); }
ilDBx::setMaxAllowedPacket | ( | ) |
Definition at line 323 of file class.ilDBx.php.
References $query, $res, and $row.
Referenced by ilDBx().
{ // GET MYSQL VERSION $query = "SHOW VARIABLES LIKE 'version'"; $res = $this->db->query($query); if(DB::isError($res)) { $this->raiseError($res->getMessage()."<br><font size=-1>SQL: ".$query."</font>", $this->error_class->FATAL); } while($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { $version = $row->Value; } // CHANG VALUE IF MYSQL VERSION > 4.0 if(substr($version,0,1) == "4") { ini_get("post_max_size"); $query = "SET GLOBAL max_allowed_packet = ".(int) ini_get("post_max_size") * 1024 * 1024; $this->db->query($query); if(DB::isError($res)) { $this->raiseError($res->getMessage()."<br><font size=-1>SQL: ".$query."</font>", $this->error_class->FATAL); } } // STORE NEW max_size in member variable $query = "SHOW VARIABLES LIKE 'max_allowed_packet'"; if(DB::isError($res)) { $this->raiseError($res->getMessage()."<br><font size=-1>SQL: ".$query."</font>", $this->error_class->FATAL); } $res = $this->db->query($query); while($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { $this->max_allowed_packet_size = $row->Value; } #var_dump("<pre>",$this->max_allowed_packet_size,"<pre>"); return true; }
ilDBx::tableColumnExists | ( | $ | a_table, | |
$ | a_column_name | |||
) |
Checks for the existence of a table column.
string | $a_table The table name which should be examined | |
string | $a_column_name The name of the column |
Definition at line 456 of file class.ilDBx.php.
ilDBx::$db |
Definition at line 55 of file class.ilDBx.php.
ilDBx::$error_class |
Definition at line 49 of file class.ilDBx.php.
ilDBx::$max_allowed_packet_size |
Definition at line 67 of file class.ilDBx.php.
ilDBx::$result |
Definition at line 61 of file class.ilDBx.php.