Public Member Functions | Data Fields

ilDBx Class Reference

Inheritance diagram for ilDBx:
Collaboration diagram for ilDBx:

Public Member Functions

 ilDBx ($dsn)
 constructor
 _ilDBx ()
 destructor
 disconnect ()
 disconnect from database
 query ($sql)
 query
 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.
 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 NOTE: Please also see modules/dateplaner/classes/class.ilCalInterface.php->setNames if you make any changes here.

Data Fields

 $error_class
 $db
 $result
 $max_allowed_packet_size

Detailed Description

Definition at line 42 of file class.ilDBx.php.


Member Function Documentation

ilDBx::_ilDBx (  ) 

destructor

Definition at line 117 of file class.ilDBx.php.

                          {
                //$this->db->disconnect();
        } //end destructor

ilDBx::_lockTables ( a_table_params  ) 

Lock existing table.

Parameters:
array (tablename => lock type READ, WRITE, READ LOCAL or LOW_PRIORITY) e.g array('tree' => 'WRITE')
Returns:
boolean

Definition at line 320 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;
        }

Here is the caller graph for this function:

ilDBx::_unlockTables (  ) 

Definition at line 336 of file class.ilDBx.php.

Referenced by ilTree::deleteTree(), ilTree::insertNode(), and ilTree::renumber().

        {
                global $ilDB;
                
                $ilDB->query('UNLOCK TABLES');

                return true;
        }

Here is the caller graph for this function:

ilDBx::checkQuerySize ( a_query  ) 

Definition at line 256 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 124 of file class.ilDBx.php.

        {
//              $this->db->disconnect();
        }

ilDBx::execute ( stmt,
data 
)

Wrapper for Pear executeMultiple.

Parameters:
resource (statement from prepare)
array multidim array of data
Returns:
mixed a new DB_result/DB_OK or a DB_Error, if fail

Definition at line 242 of file class.ilDBx.php.

References $data, and $res.

        {
                $res = $this->db->execute($stmt,$data);

                if (DB::isError($res))
                {
                        $this->raiseError($res->getMessage()."<br><font size=-1>SQL: ".$data."</font>", $this->error_class->FATAL);
                }
                else
                {
                        return $res;
                }
        }

ilDBx::executeMultiple ( stmt,
data 
)

Wrapper for Pear executeMultiple.

Parameters:
resource (statement from prepare)
array multidim array of data
Returns:
mixed a new DB_result/DB_OK or a DB_Error, if fail

Definition at line 222 of file class.ilDBx.php.

References $data, and $res.

        {
                $res = $this->db->executeMultiple($stmt,$data);

                if (DB::isError($res))
                {
                        $this->raiseError($res->getMessage()."<br><font size=-1>SQL: ".$data."</font>", $this->error_class->FATAL);
                }
                else
                {
                        return $res;
                }
        }

ilDBx::getLastInsertId (  ) 

get last insert id

Definition at line 198 of file class.ilDBx.php.

References $row, and query().

        {
                $r = $this->query("SELECT LAST_INSERT_ID()");
                $row = $r->fetchRow();

                return $row[0];
        }

Here is the call graph for this function:

ilDBx::getMySQLVersion (  ) 

get mysql version

Definition at line 348 of file class.ilDBx.php.

        {
                return mysql_get_server_info();
        }

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

Parameters:
string 
Returns:
object DB

Definition at line 180 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

Parameters:
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();
                
                // set names
                // please also see modules/dateplaner/classes/class.ilCalInterface.php->setNames
                if ($this->isMysql4_1OrHigher())
                {
                        $this->query("SET NAMES utf8");
                }

                return true;
        } //end constructor

Here is the call graph for this function:

ilDBx::isMysql4_1 (  ) 

check wether current MySQL server is version 4.1.x

Definition at line 356 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: Please also see modules/dateplaner/classes/class.ilCalInterface.php->setNames if you make any changes here.

Definition at line 373 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;
        }

Here is the caller graph for this function:

ilDBx::prepare ( query  ) 

Wrapper for Pear prepare.

Parameters:
String query
Returns:
resource

Definition at line 211 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

Parameters:
string 
Returns:
object DB

Definition at line 138 of file class.ilDBx.php.

Referenced by getLastInsertId(), and ilDBx().

        {
                $r = $this->db->query($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

Here is the caller graph for this function:

ilDBx::quote ( a_query,
null_as_empty_string = true 
)

wrapper for quote method

Definition at line 156 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 274 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;
        }

Here is the caller graph for this function:


Field Documentation

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.


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