openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 0ce2fff1d6956757925e1246ba1cceb96cd9c592
parent cf11fe62e3d2b91fa9404854c178ec732b34b5e4
Author: Jan Dankert <devnull@localhost>
Date:   Tue,  5 Dec 2017 23:56:04 +0100

Datenbank-Klassen auf Namespace umgestellt.

Diffstat:
action/LoginAction.class.php | 33+++++++++++++++++++++------------
action/StartAction.class.php | 3++-
auth/DatabaseAuth.class.php | 4+++-
auth/RememberAuth.class.php | 9+++++++--
db/DbUpdate.class.php | 2--
db/update/DBVersion000001.class.php | 2++
db/update/DBVersion000002.class.php | 2+-
db/update/DBVersion000003.class.php | 2+-
db/update/DBVersion000004.class.php | 2+-
db/update/DBVersion000005.class.php | 2+-
db/update/DBVersion000006.class.php | 2+-
db/update/DBVersion000007.class.php | 2+-
modules/database/Database.class.php | 178++++++++++++++++++++++++++++++++++++++++---------------------------------------
modules/database/DbVersion.class.php | 605+++++++++++++++++++++++++++++++++++++++----------------------------------------
modules/database/Sql.class.php | 8+++++---
modules/database/Statement.class.php | 307++++++++++++++++++++++++++++++++++++++++---------------------------------------
modules/database/driver/PDODriver.class.php | 254+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
modules/database/driver/pdo.class.php | 247-------------------------------------------------------------------------------
modules/database/require.php | 10++++++----
19 files changed, 848 insertions(+), 826 deletions(-)

diff --git a/action/LoginAction.class.php b/action/LoginAction.class.php @@ -14,12 +14,14 @@ use cms\model\Language; use cms\model\Model; +use database\Database; use DB; use DbUpdate; use Http; use InternalAuth; use Logger; use ObjectNotFoundException; +use OpenRatException; use Password; use Session; use \Html; @@ -56,13 +58,14 @@ define('PROJECTID_ADMIN',-1); class LoginAction extends Action { public $security = SECURITY_GUEST; - - - /** - * Eine Datenbankverbindugn wird aufgebaut und initalisiert. - * - * @param $dbid Datenbank-Id - */ + + + /** + * Eine Datenbankverbindugn wird aufgebaut und initalisiert. + * + * @param $dbid Datenbank-Id + * @throws OpenRatException + */ private function setDb( $dbid ) { global $conf; @@ -74,10 +77,16 @@ class LoginAction extends Action if ( is_object($db) ) $db->rollback(); - $db = new DB( $conf['database'][$dbid] ); - $db->id = $dbid; - $db->start(); // Transaktion starten. - Session::setDatabase( $db ); + try + { + $db = new Database( $conf['database'][$dbid] ); + $db->id = $dbid; + $db->start(); // Transaktion starten. + Session::setDatabase( $db ); + }catch(\Exception $e) + { + throw new OpenRatException('ERROR_DATABASE_CONNECTION',$e->getMessage() ); + } } @@ -850,7 +859,7 @@ class LoginAction extends Action if ( !is_array($conf['database'][$dbid]) ) $this->addValidationError('dbid'); - $db = new DB( $conf['database'][$dbid],true ); + $db = new Database( $conf['database'][$dbid],true ); $db->id = $dbid; // Datenbank aktualisieren, sofern notwendig. diff --git a/action/StartAction.class.php b/action/StartAction.class.php @@ -12,6 +12,7 @@ use cms\model\Language; use cms\model\Model; +use database\Database; use Logger; use Password; use Session; @@ -64,7 +65,7 @@ class StartAction extends Action $db->rollback(); } - $db = new DB( $conf['database'][$dbid] ); + $db = new Database( $conf['database'][$dbid] ); $db->id = $dbid; $db->start(); Session::setDatabase( $db ); diff --git a/auth/DatabaseAuth.class.php b/auth/DatabaseAuth.class.php @@ -1,5 +1,7 @@ <?php +use database\Database; + /** * Authentifzierung über eine externe Datenbank. * @author dankert @@ -20,7 +22,7 @@ class DatabaseAuth implements Auth if ( ! $authDbConf['enable'] ) return false; - $authdb = new DB( $authDbConf ); + $authdb = new Database( $authDbConf ); $sql = $authdb->sql( $conf['security']['authdb']['sql'] ); $algo = $authdb->sql( $conf['security']['authdb']['hash_algo'] ); diff --git a/auth/RememberAuth.class.php b/auth/RememberAuth.class.php @@ -1,5 +1,7 @@ <?php +use database\Database; + /** * Authentifizierung mit einem Login-Token. * @@ -7,7 +9,10 @@ */ class RememberAuth implements Auth { - public function username() + /** + * @return null + */ + public function username() { // Ermittelt den Benutzernamen aus den Login-Cookies. if ( isset($_COOKIE['or_username']) && @@ -20,7 +25,7 @@ class RememberAuth implements Auth $dbid = $_COOKIE['or_dbid']; global $conf; - $db = new DB( $conf['database'][$dbid] ); + $db = new Database( $conf['database'][$dbid] ); $db->id = $dbid; $db->start(); Session::setDatabase($db); diff --git a/db/DbUpdate.class.php b/db/DbUpdate.class.php @@ -22,8 +22,6 @@ class DbUpdate if ( ! $db->conf['auto_update']) Http::serverError('DB Update necessary.',"DB-Version is $version, but this is OpenRat ".OR_VERSION." which needs the version ".OR_DB_SUPPORTED_VERSION ); - require(OR_DBCLASSES_DIR.'DbVersion.class.php'); - for( $installVersion = $version + 1; $installVersion <= OR_DB_SUPPORTED_VERSION; $installVersion++ ) { if ( $installVersion > 2 ) diff --git a/db/update/DBVersion000001.class.php b/db/update/DBVersion000001.class.php @@ -1,5 +1,7 @@ <?php +use database\DbVersion; + /** * Baseline database structure. diff --git a/db/update/DBVersion000002.class.php b/db/update/DBVersion000002.class.php @@ -1,5 +1,5 @@ <?php - +use database\DbVersion; /** * new table: version. * diff --git a/db/update/DBVersion000003.class.php b/db/update/DBVersion000003.class.php @@ -1,5 +1,5 @@ <?php - +use database\DbVersion; /** * Dummy version. * @author dankert diff --git a/db/update/DBVersion000004.class.php b/db/update/DBVersion000004.class.php @@ -1,5 +1,5 @@ <?php - +use database\DbVersion; /** * Add Columns for user language and user timezone. diff --git a/db/update/DBVersion000005.class.php b/db/update/DBVersion000005.class.php @@ -1,5 +1,5 @@ <?php - +use database\DbVersion; /** * Security enhancements. diff --git a/db/update/DBVersion000006.class.php b/db/update/DBVersion000006.class.php @@ -1,5 +1,5 @@ <?php - +use database\DbVersion; /** * Security enhancements. diff --git a/db/update/DBVersion000007.class.php b/db/update/DBVersion000007.class.php @@ -1,5 +1,5 @@ <?php - +use database\DbVersion; /** * Security enhancements. diff --git a/modules/database/Database.class.php b/modules/database/Database.class.php @@ -1,21 +1,24 @@ <?php -// OpenRat Content Management System -// Copyright (C) 2002-2006 Jan Dankert, jandankert@jandankert.de -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - +// OpenRat Content Management System +// Copyright (C) 2002-2006 Jan Dankert, jandankert@jandankert.de +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +namespace database; +use Logger; +use RuntimeException; /** * Darstellung einer Datenbank-Verbindung. @@ -28,41 +31,41 @@ * @author Jan Dankert * @package openrat.database */ -class DB -{ - /** - * Datenbank-Id. - * - * @var String - */ +class Database +{ + /** + * Datenbank-Id. + * + * @var String + */ var $id; - - /** - * Konfiguration der Datenbank-Verbindung - * - * @var Array - */ + + /** + * Konfiguration der Datenbank-Verbindung + * + * @var Array + */ var $conf; - - /** - * Kennzeichen, ob die Datenbank verf�gbar ist. - * - * @var Boolean - */ + + /** + * Kennzeichen, ob die Datenbank verf�gbar ist. + * + * @var Boolean + */ var $available; - - /** - * Enth�lt eine Fehlermeldung (sofern verf�gbar). - * - * @var String - */ - var $error; + + /** + * Enth�lt eine Fehlermeldung (sofern verf�gbar). + * + * @var String + */ + var $error; - /** + /** * Client. - * Enth�lt ein Objekt der Klasse db_<type>. - * - * @var Object + * Enth�lt ein Objekt der Klasse db_<type>. + * + * @var Object */ var $client; @@ -70,21 +73,21 @@ class DB * Schalter, ob eine Transaktion begonnen wurde. * @var boolean */ - var $transactionInProgress = false; + var $transactionInProgress = false; - - /** - * Kontruktor. - * Erwartet die Datenbank-Konfiguration als Parameter. - * - * @param Array Konfiguration der Verbindung + + /** + * Kontruktor. + * Erwartet die Datenbank-Konfiguration als Parameter. + * + * @param Array Konfiguration der Verbindung * @param boolean admin Wenn es eine Admin-DB-Verbindung werden soll, die auch DDL ausfuehren darf */ - public function DB( $dbconf,$admin=false ) + public function __construct( $dbconf,$admin=false ) { global $conf; - - $this->conf = $dbconf + $conf['database-default']['defaults']; // linksstehender Operator hat Priorität! + + $this->conf = $dbconf + $conf['database-default']['defaults']; // linksstehender Operator hat Priorität! if ( $admin ) { @@ -93,50 +96,49 @@ class DB $this->conf = $this->conf['update'] + $this->conf; // linksstehender Operator hat Priorität! } - $this->connect(); + $this->connect(); } - - /** - * Verbindung zur Datenbank aufbauen. - * - * @return Status + + /** + * Verbindung zur Datenbank aufbauen. + * + * @return Status */ public function connect() - { - // Ausfuehren des Systemkommandos vor Verbindungsaufbau - if ( !empty($this->conf['cmd'])) - { - $ausgabe = array(); - $rc = false; - - Logger::debug("Database command executing: ".$this->conf['cmd']); - exec( $this->conf['cmd'],$ausgabe,$rc ); - - foreach( $ausgabe as $zeile ) - Logger::debug("Database command output: ".$zeile); - - if ( $rc != 0 ) - { - throw new OpenRatException( 'ERROR_DATABASE_CONNECTION','Command failed: '.implode("",$ausgabe) ); - } - } - - $type = $this->conf['type']; - $classname = 'db_'.$type; + { + // Ausfuehren des Systemkommandos vor Verbindungsaufbau + if ( !empty($this->conf['cmd'])) + { + $ausgabe = array(); + $rc = false; + + Logger::debug("Database command executing: ".$this->conf['cmd']); + exec( $this->conf['cmd'],$ausgabe,$rc ); + + foreach( $ausgabe as $zeile ) + Logger::debug("Database command output: ".$zeile); + + if ( $rc != 0 ) + { + throw new RuntimeException( 'Command failed: '.implode("",$ausgabe) ); + } + } + $type = $this->conf['type']; + $classname = 'database\\driver\\'.strtoupper($type).'Driver'; if ( ! class_exists($classname) ) { $this->available = false; - throw new OpenRatException( 'ERROR_DATABASE_CONNECTION','Database type "'.$type.'" is not available'); + throw new RuntimeException( "Database type '$type' is not available, class '$classname' was not found"); } - + $f = new driver\PDODriver(); // Client instanziieren $this->client = new $classname; $this->client->connect( $this->conf ); - + // SQL nach Verbindungsaufbau ausfuehren. if ( ! empty($this->conf['connection_sql']) ) { @@ -148,7 +150,7 @@ class DB if ( ! $ok ) { - throw new OpenRatException( 'ERROR_DATABASE_CONNECTION',"Could not execute connection-query '".$cmd."'"); + throw new RuntimeException( "Could not execute connection-query '".$cmd."'"); } } diff --git a/modules/database/DbVersion.class.php b/modules/database/DbVersion.class.php @@ -1,315 +1,304 @@ <?php -define('OR_DB_INDEX_PREFIX' ,'IX'); -define('OR_DB_CONSTRAINT_PREFIX','FK'); - -abstract class DbVersion -{ - private $db; - private $tablePrefix; - private $tableSuffix; - private $dbmsType; - - function DbVersion( $db ) - { - $this->db = $db; - - switch( $db->conf['type'] ) - { - case 'mysql': - case 'mysqli': - $this->dbmsType = 'mysql'; - break; - case 'postgresql': - $this->dbmsType = 'postgresql'; - break; - case 'sqlite': - case 'sqlite3': - $this->dbmsType = 'sqlite'; - break; - case 'pdo': - $dsnParts = explode(':',$db->conf['dsn']); - switch( $dsnParts[0] ) - { - case 'mysql': - $this->dbmsType = 'mysql'; - break; - case 'pgsql': - $this->dbmsType = 'postgresql'; - break; - case 'sqlite': - $this->dbmsType = 'sqlite'; - break; - default: - Http::serverError('Datebase Configuration Error','Unknown DBMS in PDO-DSN: '.$dsnParts[0]); - } - break; - default: - Http::serverError('Datebase Configuration Error','Unknown DBMS type: '.$db->conf['type'] ); - } - - $this->tablePrefix = $db->conf['prefix']; - $this->tableSuffix = $db->conf['suffix']; - } - - // Muss überschrieben werden! - abstract function update(); - - - - - - - - - protected function getTableName( $name ) - { - return $this->tablePrefix.$name.$this->tableSuffix; - } - - - /** - * Erzeugt eine neue Tabelle. - * Die neue Tabelle enthält bereits eine Spalte "id" (da eine leere Tabelle i.d.R. nicht zulässig ist). - */ - function addTable( $tableName ) - { - $tableName = $this->getTableName($tableName); - - $table_opts = $this->dbmsType=='mysql'?' ENGINE=InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci':''; - - $ddl = $this->db->sql('CREATE TABLE '.$tableName.'(id INTEGER)'.$table_opts.';'); - // The syntax 'TYPE = InnoDB' was deprecated in MySQL 5.0 and was removed in MySQL 5.1 and later versions. - - $ddl->query(); - } - - - # Creating a new column - # param 1: column name - # param 2: type (available are: INT,VARCHAR,TEXT,BLOB) - # param 3: size (number value) - # param 4: default (number value) - # param 5: nullable (available are: J,N) - function addColumn($tableName,$columnName,$type,$size,$default,$nullable) - { - $table = $this->getTableName($tableName); - - $type = strtoupper($type); - switch( $type ) - { - case 'INT': - switch( $this->dbmsType ) - { - case 'mysql': - if ( $size == 1 ) - $dbmsInternalType = 'TINYINT'; - else - $dbmsInternalType = 'INT'; - break; - - case 'oracle': - $dbmsInternalType = 'NUMBER'; - break; - - default: - $dbmsInternalType = 'INTEGER'; - - } - break; - - case 'VARCHAR': - switch( $this->dbmsType ) - { - default: - $dbmsInternalType = 'VARCHAR'; - - } - break; - - case 'TEXT': - switch( $this->dbmsType ) - { - case 'mysql': - $dbmsInternalType = 'MEDIUMTEXT'; - break; - - case 'oracle': - $dbmsInternalType = 'CLOB'; - break; - - default: - $dbmsInternalType = 'TEXT'; - - } - break; - - case 'BLOB': - switch( $this->dbmsType ) - { - case 'mysql': - $dbmsInternalType = 'MEDIUMBLOB'; - break; - - case 'oracle': - $dbmsInternalType = 'CLOB'; - break; - - case 'postgresql': - $dbmsInternalType = 'TEXT'; - break; - - case 'sqlite': - $dbmsInternalType = 'TEXT'; - break; - - default: - $dbmsInternalType = 'BLOB'; - - } - break; - default: - Http::serverError('Datebase Configuration Error','Unknown Column type: '.$type ); - } - - if ( $this->dbmsType == 'oracle') - { - // TEXT-columns should be nullable in Oracle, because empty strings are treated as NULL - if ( $type=='VARCHAR' || $type=='TEXT') - $nullable = true; - - } - - $ddl = $this->db->sql('ALTER TABLE '.$table. - ' ADD COLUMN '.$columnName.' '.$dbmsInternalType.($size!=null?'('.$size.')':''). - ($default!==null?' DEFAULT '.(is_string($default)?"'":'').$default.(is_string($default)?"'":''):''). - ' '.($nullable?'NULL':'NOT NULL').';' - ); - $ddl->query(); - - } - - - - function addPrimaryKey( $tableName,$columnNames) - { - $table = $this->getTableName($tableName); - - if ( !is_array($columnNames) ) - $columnNames = explode(',',$columnNames); - - $ddl = $this->db->sql('ALTER TABLE '.$table.' ADD PRIMARY KEY ('.implode(',',$columnNames).');'); - $ddl->query(); - - } - - - - # Creating a unique key - # param 1: name of index column. Seperate multiple columns with ',' - function addIndex($tableName,$columnNames,$unique=false) - { - $table = $this->getTableName($tableName); - - if ( !is_array($columnNames) ) - $columnNames = explode(',',$columnNames); - - $indexName = $this->tablePrefix.OR_DB_INDEX_PREFIX.'_'.$tableName.'_'.implode('_',$columnNames).$this->tableSuffix; - +namespace { + define('OR_DB_INDEX_PREFIX', 'IX'); + define('OR_DB_CONSTRAINT_PREFIX', 'FK'); +} + +namespace database { + + use Http; + + abstract class DbVersion + { + private $db; + private $tablePrefix; + private $tableSuffix; + private $dbmsType; + + public function __construct($db) + { + $this->db = $db; + + switch ($db->conf['type']) { + case 'mysql': + case 'mysqli': + $this->dbmsType = 'mysql'; + break; + case 'postgresql': + $this->dbmsType = 'postgresql'; + break; + case 'sqlite': + case 'sqlite3': + $this->dbmsType = 'sqlite'; + break; + case 'pdo': + $dsnParts = explode(':', $db->conf['dsn']); + switch ($dsnParts[0]) { + case 'mysql': + $this->dbmsType = 'mysql'; + break; + case 'pgsql': + $this->dbmsType = 'postgresql'; + break; + case 'sqlite': + $this->dbmsType = 'sqlite'; + break; + default: + Http::serverError('Datebase Configuration Error', 'Unknown DBMS in PDO-DSN: ' . $dsnParts[0]); + } + break; + default: + Http::serverError('Datebase Configuration Error', 'Unknown DBMS type: ' . $db->conf['type']); + } + + $this->tablePrefix = $db->conf['prefix']; + $this->tableSuffix = $db->conf['suffix']; + } + + // Muss überschrieben werden! + abstract function update(); + + + protected function getTableName($name) + { + return $this->tablePrefix . $name . $this->tableSuffix; + } + + + /** + * Erzeugt eine neue Tabelle. + * Die neue Tabelle enthält bereits eine Spalte "id" (da eine leere Tabelle i.d.R. nicht zulässig ist). + */ + function addTable($tableName) + { + $tableName = $this->getTableName($tableName); + + $table_opts = $this->dbmsType == 'mysql' ? ' ENGINE=InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci' : ''; + + $ddl = $this->db->sql('CREATE TABLE ' . $tableName . '(id INTEGER)' . $table_opts . ';'); + // The syntax 'TYPE = InnoDB' was deprecated in MySQL 5.0 and was removed in MySQL 5.1 and later versions. + + $ddl->query(); + } + + + # Creating a new column + # param 1: column name + # param 2: type (available are: INT,VARCHAR,TEXT,BLOB) + # param 3: size (number value) + # param 4: default (number value) + # param 5: nullable (available are: J,N) + function addColumn($tableName, $columnName, $type, $size, $default, $nullable) + { + $table = $this->getTableName($tableName); + + $type = strtoupper($type); + switch ($type) { + case 'INT': + switch ($this->dbmsType) { + case 'mysql': + if ($size == 1) + $dbmsInternalType = 'TINYINT'; + else + $dbmsInternalType = 'INT'; + break; + + case 'oracle': + $dbmsInternalType = 'NUMBER'; + break; + + default: + $dbmsInternalType = 'INTEGER'; + + } + break; + + case 'VARCHAR': + switch ($this->dbmsType) { + default: + $dbmsInternalType = 'VARCHAR'; + + } + break; + + case 'TEXT': + switch ($this->dbmsType) { + case 'mysql': + $dbmsInternalType = 'MEDIUMTEXT'; + break; + + case 'oracle': + $dbmsInternalType = 'CLOB'; + break; + + default: + $dbmsInternalType = 'TEXT'; + + } + break; + + case 'BLOB': + switch ($this->dbmsType) { + case 'mysql': + $dbmsInternalType = 'MEDIUMBLOB'; + break; + + case 'oracle': + $dbmsInternalType = 'CLOB'; + break; + + case 'postgresql': + $dbmsInternalType = 'TEXT'; + break; + + case 'sqlite': + $dbmsInternalType = 'TEXT'; + break; + + default: + $dbmsInternalType = 'BLOB'; + + } + break; + default: + Http::serverError('Datebase Configuration Error', 'Unknown Column type: ' . $type); + } + + if ($this->dbmsType == 'oracle') { + // TEXT-columns should be nullable in Oracle, because empty strings are treated as NULL + if ($type == 'VARCHAR' || $type == 'TEXT') + $nullable = true; + + } + + $ddl = $this->db->sql('ALTER TABLE ' . $table . + ' ADD COLUMN ' . $columnName . ' ' . $dbmsInternalType . ($size != null ? '(' . $size . ')' : '') . + ($default !== null ? ' DEFAULT ' . (is_string($default) ? "'" : '') . $default . (is_string($default) ? "'" : '') : '') . + ' ' . ($nullable ? 'NULL' : 'NOT NULL') . ';' + ); + $ddl->query(); + + } + + + function addPrimaryKey($tableName, $columnNames) + { + $table = $this->getTableName($tableName); + + if (!is_array($columnNames)) + $columnNames = explode(',', $columnNames); + + $ddl = $this->db->sql('ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . implode(',', $columnNames) . ');'); + $ddl->query(); + + } + + + + # Creating a unique key + # param 1: name of index column. Seperate multiple columns with ',' + function addIndex($tableName, $columnNames, $unique = false) + { + $table = $this->getTableName($tableName); + + if (!is_array($columnNames)) + $columnNames = explode(',', $columnNames); + + $indexName = $this->tablePrefix . OR_DB_INDEX_PREFIX . '_' . $tableName . '_' . implode('_', $columnNames) . $this->tableSuffix; + // if [ "$type" == "oracle" ]; then // cnt=$(($cnt+1)) // echo "CREATE UNIQUE INDEX ${prefix}uidx_${cnt}" >> $outfile // else - - $ddl = $this->db->sql('CREATE '.($unique?'UNIQUE ':'').'INDEX '.$indexName.' ON '.$table.' ('.implode(',',$columnNames).');'); - $ddl->query(); - - } - - - /** - * Creating a unique key. - * param 1: name of index column. Seperate multiple columns with ',' - * - */ - function addUniqueIndex($tableName,$columnNames) - { - $this->addIndex( $tableName,$columnNames,true ); - } - - - # Creating a foreign key - # param 1: column name - # param 2: target table name - # param 3: target column name - function addConstraint($tableName,$columnName,$targetTableName,$targetColumnName) - { - $table = $this->getTableName($tableName); - $targetTable = $this->getTableName($targetTableName); - - $constraintName = $this->tablePrefix.OR_DB_CONSTRAINT_PREFIX.'_'.$tableName.$this->tableSuffix.'_'.$columnName; - - // Oracle doesn't support "ON DELETE RESTRICT"-Statements, but its the default. - - $ddl = $this->db->sql('ALTER TABLE '.$table.' ADD CONSTRAINT '.$constraintName.' FOREIGN KEY ('.$columnName.') REFERENCES '.$targetTable.' ('.$targetColumnName.') ON DELETE RESTRICT ON UPDATE RESTRICT;'); - $ddl->query(); - } - - - - function dropTable( $tableName) - { - $table = $this->getTableName($tableName); - - $ddl = $this->db->sql('DROP TABLE '.$table.';' ); - $ddl->query(); - } - - function dropColumn( $tableName,$columnName ) - { - $table = $this->getTableName($tableName); - - $ddl = $this->db->sql('ALTER TABLE '.$table.' DROP COLUMN '.$columnName.';'); - $ddl->query(); - - - } - - function dropIndex( $indexName,$unique=false) - { - $ddl = $this->db->sql('DROP'.($unique?' UNIQUE':'').' INDEX '.$indexName.';' ); - $ddl->query(); - } - - function dropUniqueIndex( $indexName) - { - $this->dropIndex( $indexName,true ); - } - - function dropPrimaryKey( $tableName,$columnNames ) - { - $table = $this->getTableName($tableName); - - if ( !is_array($columnNames) ) - $columnNames = explode(',',$columnNames); - - $ddl = $this->db->sql('ALTER TABLE '.$table.' DROP PRIMARY KEY('.implode(',',$columnNames).')'); - $ddl->query(); - } - - - function dropConstraint( $constraintName) - { - $ddl = $this->db->sql('DROP CONSTRAINT '.$constraintName.';' ); - $ddl->query(); - } - - - function getDb() - { - return $this->db; - } -} + $ddl = $this->db->sql('CREATE ' . ($unique ? 'UNIQUE ' : '') . 'INDEX ' . $indexName . ' ON ' . $table . ' (' . implode(',', $columnNames) . ');'); + $ddl->query(); + + } + + + /** + * Creating a unique key. + * param 1: name of index column. Seperate multiple columns with ',' + * + */ + function addUniqueIndex($tableName, $columnNames) + { + $this->addIndex($tableName, $columnNames, true); + } + + + # Creating a foreign key + # param 1: column name + # param 2: target table name + # param 3: target column name + function addConstraint($tableName, $columnName, $targetTableName, $targetColumnName) + { + $table = $this->getTableName($tableName); + $targetTable = $this->getTableName($targetTableName); + + $constraintName = $this->tablePrefix . OR_DB_CONSTRAINT_PREFIX . '_' . $tableName . $this->tableSuffix . '_' . $columnName; + + // Oracle doesn't support "ON DELETE RESTRICT"-Statements, but its the default. + + $ddl = $this->db->sql('ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $constraintName . ' FOREIGN KEY (' . $columnName . ') REFERENCES ' . $targetTable . ' (' . $targetColumnName . ') ON DELETE RESTRICT ON UPDATE RESTRICT;'); + $ddl->query(); + } + + + function dropTable($tableName) + { + $table = $this->getTableName($tableName); + + $ddl = $this->db->sql('DROP TABLE ' . $table . ';'); + $ddl->query(); + } + + function dropColumn($tableName, $columnName) + { + $table = $this->getTableName($tableName); + + $ddl = $this->db->sql('ALTER TABLE ' . $table . ' DROP COLUMN ' . $columnName . ';'); + $ddl->query(); + + + } + + function dropIndex($indexName, $unique = false) + { + $ddl = $this->db->sql('DROP' . ($unique ? ' UNIQUE' : '') . ' INDEX ' . $indexName . ';'); + $ddl->query(); + } + + function dropUniqueIndex($indexName) + { + $this->dropIndex($indexName, true); + } + + function dropPrimaryKey($tableName, $columnNames) + { + $table = $this->getTableName($tableName); + + if (!is_array($columnNames)) + $columnNames = explode(',', $columnNames); + + $ddl = $this->db->sql('ALTER TABLE ' . $table . ' DROP PRIMARY KEY(' . implode(',', $columnNames) . ')'); + $ddl->query(); + } + + + function dropConstraint($constraintName) + { + $ddl = $this->db->sql('DROP CONSTRAINT ' . $constraintName . ';'); + $ddl->query(); + } + + + function getDb() + { + return $this->db; + } -?>- \ No newline at end of file + } +}+ \ No newline at end of file diff --git a/modules/database/Sql.class.php b/modules/database/Sql.class.php @@ -16,7 +16,9 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - +namespace database; +use Logger; +use RuntimeException; /** * SQL-Anweisung.<br> @@ -73,7 +75,7 @@ class Sql /** * Erzeugt ein SQL-Objekt und analysiert die SQL-Anfrage. */ - function Sql( $query = '' ) + function __construct( $query = '' ) { $this->parseSourceQuery( $query ); } @@ -97,7 +99,7 @@ class Sql $nameParam = substr($query,$posKlLinks+1,$posKlRechts-$posKlLinks-1); // Name Parameter if ( isset($this->param[$nameParam ])) - throw new RuntimeException( 'Parameter '.$nameParam.' in Query mehrfach vorhanden.' ); + throw new RuntimeException( 'Parameter '.$nameParam.' in Query mehrfach vorhanden.' ); $this->param[$nameParam] = $posKlLinks; diff --git a/modules/database/Statement.class.php b/modules/database/Statement.class.php @@ -1,21 +1,24 @@ <?php -// OpenRat Content Management System -// Copyright (C) 2002-2006 Jan Dankert, jandankert@jandankert.de -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - +// OpenRat Content Management System +// Copyright (C) 2002-2006 Jan Dankert, jandankert@jandankert.de +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +namespace database; +use Exception; +use RuntimeException; /** * Darstellung einer Datenbank-Abfrage. @@ -24,20 +27,20 @@ * @package openrat.database */ class Statement -{ - - /** - * SQL-Objekt. - * - * @var SQL - */ - var $sql; +{ + + /** + * SQL-Objekt. + * + * @var SQL + */ + var $sql; - /** + /** * Client. - * Enth�lt ein Objekt der Klasse db_<type>. - * - * @var Object + * Enth�lt ein Objekt der Klasse db_<type>. + * + * @var Object */ var $client; @@ -48,14 +51,14 @@ class Statement */ var $conf; - /** - * Kontruktor. - * Erwartet die Datenbank-Konfiguration als Parameter. - * - * @param Array Konfiguration der Verbindung - * @return Status 'true' wenn Verbindung erfolgreich aufgebaut. + /** + * Kontruktor. + * Erwartet die Datenbank-Konfiguration als Parameter. + * + * @param Array Konfiguration der Verbindung + * @return Status 'true' wenn Verbindung erfolgreich aufgebaut. */ - public function Statement( $sql, $client,$conf ) + public function __construct( $sql, $client,$conf ) { // Tabellen-Praefixe ergaenzen. $this->conf = $conf; @@ -66,20 +69,20 @@ class Statement $this->sql = new Sql( $sql ); - // Vorbereitete Datenbankabfrage ("Prepared Statement") - $this->client->clear(); - - // Statement an die Datenbank schicken - $this->client->prepare( $this->sql->query,$this->sql->param ); + // Vorbereitete Datenbankabfrage ("Prepared Statement") + $this->client->clear(); + + // Statement an die Datenbank schicken + $this->client->prepare( $this->sql->query,$this->sql->param ); } - - /** - * Ausfuehren einer Datenbankanfrage. - * - * @param SQL-Objekt - * @return Object (Result) + + /** + * Ausfuehren einer Datenbankanfrage. + * + * @param SQL-Objekt + * @return Object (Result) */ public function query( ) { @@ -87,32 +90,32 @@ class Statement } - /** - * Ausfuehren einer Datenbankanfrage. - * - * @param SQL-Objekt - * @return Object (Result) - */ - public function execute( ) - { - // Ausfuehren... - $result = $this->client->query($this->sql); - - if ( $result === FALSE ) - { - throw new RuntimeException( 'Database error: '.$this->client->error); - } - - return $result; - } + /** + * Ausfuehren einer Datenbankanfrage. + * + * @param SQL-Objekt + * @return Object (Result) + */ + public function execute( ) + { + // Ausfuehren... + $result = $this->client->query($this->sql); - - /** - * Ermittelt genau 1 Datenbankergebnis aus einer SQL-Anfrage. - * Falls es mehrere Treffer gibt, wird die 1. Spalte aus der 1. Zeile genommen. - * - * @param String $this->query - * @return String + if ( $result === FALSE ) + { + throw new RuntimeException( 'Database error: '.$this->client->error); + } + + return $result; + } + + + /** + * Ermittelt genau 1 Datenbankergebnis aus einer SQL-Anfrage. + * Falls es mehrere Treffer gibt, wird die 1. Spalte aus der 1. Zeile genommen. + * + * @param String $this->query + * @return String */ public function &getOne() { @@ -130,12 +133,12 @@ class Statement return $row[ $keys[0] ]; } - - /** - * Ermittelt eine Zeile aus der Datenbank. - * - * @param String $this->query - * @return Array + + /** + * Ermittelt eine Zeile aus der Datenbank. + * + * @param String $this->query + * @return Array */ public function &getRow() { @@ -150,12 +153,12 @@ class Statement return $row; } - - /** - * Ermittelt eine (die 1.) Spalte aus dem Datenbankergebnis. - * - * @param String $this->query - * @return Array + + /** + * Ermittelt eine (die 1.) Spalte aus dem Datenbankergebnis. + * + * @param String $this->query + * @return Array */ public function &getCol() { @@ -177,13 +180,13 @@ class Statement return $col; } - - /** - * Ermittelt ein assoziatives Array aus der Datenbank. - * - * @param String $this->query - * @param Boolean $force_array - * @return Array + + /** + * Ermittelt ein assoziatives Array aus der Datenbank. + * + * @param String $this->query + * @param Boolean $force_array + * @return Array */ public function &getAssoc() { @@ -199,8 +202,8 @@ class Statement if ( empty($row) ) break; - $keys = array_keys($row); - $key1 = $keys[0]; + $keys = array_keys($row); + $key1 = $keys[0]; $id = $row[$key1]; if ( count($row) > 2 || $force_array ) @@ -221,12 +224,12 @@ class Statement return $results; } - - /** - * Ermittelt alle Datenbankergebniszeilen. - * - * @param String $this->query - * @return Array + + /** + * Ermittelt alle Datenbankergebniszeilen. + * + * @param String $this->query + * @return Array */ public function &getAll() { @@ -266,59 +269,59 @@ class Statement } - /** - * Setzt eine Ganzzahl als Parameter.<br> - * - * @param name Name des Parameters - * @param value Inhalt - */ - function setInt( $name,$value ) - { - $this->client->bind( $name, (int)$value ); - } - - - - /** - * Setzt eine Zeichenkette als Parameter.<br> - * - * @param name Name des Parameters - * @param value Inhalt - */ - function setString( $name,$value ) - { - $this->client->bind( $name, (string)$value ); - } - - - - /** - * Setzt einen bool'schen Wert als Parameter.<br> - * Ist der Parameterwert wahr, dann wird eine 1 gesetzt. Sonst 0.<br> - * - * @param name Name des Parameters - * @param value Inhalt - */ - function setBoolean( $name,$value ) - { - if ( $value ) - $this->setInt( $name,1 ); - else - $this->setInt( $name,0 ); - } - - - - /** - * Setzt einen Parameter auf den Wert <code>null</code>.<br> - * - * @param name Name des Parameters - */ - function setNull( $name ) - { - $this->client->bind( $name, null ); - } - + /** + * Setzt eine Ganzzahl als Parameter.<br> + * + * @param name Name des Parameters + * @param value Inhalt + */ + function setInt( $name,$value ) + { + $this->client->bind( $name, (int)$value ); + } + + + + /** + * Setzt eine Zeichenkette als Parameter.<br> + * + * @param name Name des Parameters + * @param value Inhalt + */ + function setString( $name,$value ) + { + $this->client->bind( $name, (string)$value ); + } + + + + /** + * Setzt einen bool'schen Wert als Parameter.<br> + * Ist der Parameterwert wahr, dann wird eine 1 gesetzt. Sonst 0.<br> + * + * @param name Name des Parameters + * @param value Inhalt + */ + function setBoolean( $name,$value ) + { + if ( $value ) + $this->setInt( $name,1 ); + else + $this->setInt( $name,0 ); + } + + + + /** + * Setzt einen Parameter auf den Wert <code>null</code>.<br> + * + * @param name Name des Parameters + */ + function setNull( $name ) + { + $this->client->bind( $name, null ); + } + } diff --git a/modules/database/driver/PDODriver.class.php b/modules/database/driver/PDODriver.class.php @@ -0,0 +1,253 @@ +<?php + +// +// +----------------------------------------------------------------------+ +// | PHP version 4.0 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2001 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.02 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Stig Bakken <ssb@fast.no> | +// | Jan Dankert <phpdb@jandankert.de> | +// +----------------------------------------------------------------------+ +// +namespace database\driver; + +use \Logger; +use \OpenRatException; +use \PDO; +use \PDOException; +use \RuntimeException; + +/** + * Datenbank-abhaengige Methoden fuer PDO. + * + * @author Jan Dankert + * @version $Revision: 1.5 $ + * @package openrat.database + */ +class PDODriver +{ + /** + * Die PDO-Verbindung. + * + * @var Resource + */ + var $connection; + + /** + * Datenbank-Fehler. + * + * @var String + */ + var $error; + + var $lowercase = false; + + var $params; + + + function connect( $conf ) + { + $url = $conf['dsn' ]; + $user = $conf['user' ]; + $pw = $conf['password']; + + if ( !empty($conf['convert_to_lowercase']) ) + $this->lowercase = true; + + $options = array(); + foreach( $conf as $c ) + if ( is_string($c) && substr($c,0,7) == 'option_' ) + $options[substr($c,8)] = $conf[$c]; + + if ( $conf['persistent']) + $options[ PDO::ATTR_PERSISTENT ] = true; + + //if ( !$conf['prepare']) <- unused... + // From the docs: + // try to use native prepared statements (if FALSE). + // It will always fall back to emulating the prepared statement if the driver cannot successfully prepare the current query + $options[ PDO::ATTR_EMULATE_PREPARES ] = false; + + // Convert numeric values to strings when fetching => NO + $options[ PDO::ATTR_STRINGIFY_FETCHES ] = false; + $options[ PDO::ATTR_AUTOCOMMIT ] = false; + + // We like Exceptions + $options[ PDO::ERRMODE_EXCEPTION ] = true; + $options[ PDO::ATTR_DEFAULT_FETCH_MODE ] = PDO::FETCH_ASSOC; + + $this->connection = new PDO($url, $user, $pw, $options); + + if ( !is_object($this->connection) ) + throw new OpenRatException( 'DATABASE_ERROR_CONNECTION',"Could not connect to database on host $host. ".PDO::errorInfo() ); + + return true; + } + + + + function disconnect() + { + $this->connection = null; + return true; + } + + + + function query($query) + { + $erg = $this->stmt->execute(); + + if ( $erg === false ) + { + throw new RuntimeException( 'Could not execute prepared statement "'.$query->query.'": '.implode('/',$this->stmt->errorInfo()) ); + } + + return $this->stmt; + } + + + function fetchRow( $result, $rownum ) + { + $row = $this->stmt->fetch( PDO::FETCH_ASSOC ); + +/* + * + + + if(intval(@$row['id'])==1) + { + echo "Hallo:"; + +// echo "\n";print_r($row)."\n"; + var_dump($row); + echo " ist... ".gettype($row); + + } + + */ + + + if ( is_array($row) && $this->lowercase ) + $row = array_change_key_case($row); + + return $row; + } + + + function freeResult($result) + { + return true; + } + + + function prepare( $query,$param) + { + $this->params = $param; + $offset = 0; + foreach( $param as $name=>$pos) + { + $name = ':'.$name; + $pos += $offset; + $query = substr($query,0,$pos).$name.substr($query,$pos); + + $offset = $offset + strlen($name); + } + + Logger::debug('PDO: SQL-before-preparation: '.$query); + + $this->stmt = $this->connection->prepare($query); + + if ( $this->stmt === false ) + throw new RuntimeException('Could not prepare statement: '.$query.' Cause: '.implode('/',$this->connection->errorInfo()) ); + + } + + + + function bind( $param,$value ) + { + $name = ':'.$param; + + if ( is_string($value) ) + $type = PDO::PARAM_STR; + elseif( is_int($value)) + $type = PDO::PARAM_INT; + elseif( is_null($value)) + $type = PDO::PARAM_NULL; + else + throw new RuntimeException( 'Unknown type' ); + + $this->stmt->bindValue($name,$value,$type); + + Logger::debug('PDO: SQL-Binding of parameter '.$name); + } + + + + /** + * Startet eine Transaktion. + */ + function start() + { + $this->connection->beginTransaction(); + } + + + + /** + * Beendet eine Transaktion. + */ + function commit() + { + $this->connection->commit(); + } + + + /** + * Bricht eine Transaktion ab. + */ + function rollback() + { + try + { + $this->connection->rollBack(); + } + catch ( PDOException $e ) + { + // Kommt vor, wenn keine Transaktion existiert. + } + } + + + + /** + * Setzt die letzte Abfrage zurueck. + */ + function clear() + { + $this->params = array(); + } + + + /** + * Why this? See http://e-mats.org/2008/07/fatal-error-exception-thrown-without-a-stack-frame-in-unknown-on-line-0/ + * + * @return array + */ + function __sleep() { + return array(); + } + +} + +?>+ \ No newline at end of file diff --git a/modules/database/driver/pdo.class.php b/modules/database/driver/pdo.class.php @@ -1,246 +0,0 @@ -<?php - -// -// +----------------------------------------------------------------------+ -// | PHP version 4.0 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2001 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 2.02 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/2_02.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Authors: Stig Bakken <ssb@fast.no> | -// | Jan Dankert <phpdb@jandankert.de> | -// +----------------------------------------------------------------------+ -// - -/** - * Datenbank-abhaengige Methoden fuer PDO. - * - * @author Jan Dankert - * @version $Revision: 1.5 $ - * @package openrat.database - */ -class DB_pdo -{ - /** - * Die PDO-Verbindung. - * - * @var Resource - */ - var $connection; - - /** - * Datenbank-Fehler. - * - * @var String - */ - var $error; - - var $lowercase = false; - - var $params; - - - function connect( $conf ) - { - $url = $conf['dsn' ]; - $user = $conf['user' ]; - $pw = $conf['password']; - - if ( !empty($conf['convert_to_lowercase']) ) - $this->lowercase = true; - - $options = array(); - foreach( $conf as $c ) - if ( is_string($c) && substr($c,0,7) == 'option_' ) - $options[substr($c,8)] = $conf[$c]; - - if ( $conf['persistent']) - $options[ PDO::ATTR_PERSISTENT ] = true; - - //if ( !$conf['prepare']) <- unused... - // From the docs: - // try to use native prepared statements (if FALSE). - // It will always fall back to emulating the prepared statement if the driver cannot successfully prepare the current query - $options[ PDO::ATTR_EMULATE_PREPARES ] = false; - - // Convert numeric values to strings when fetching => NO - $options[ PDO::ATTR_STRINGIFY_FETCHES ] = false; - $options[ PDO::ATTR_AUTOCOMMIT ] = false; - - // We like Exceptions - $options[ PDO::ERRMODE_EXCEPTION ] = true; - $options[ PDO::ATTR_DEFAULT_FETCH_MODE ] = PDO::FETCH_ASSOC; - - $this->connection = new PDO($url, $user, $pw, $options); - - if ( !is_object($this->connection) ) - throw new OpenRatException( 'DATABASE_ERROR_CONNECTION',"Could not connect to database on host $host. ".PDO::errorInfo() ); - - return true; - } - - - - function disconnect() - { - $this->connection = null; - return true; - } - - - - function query($query) - { - $erg = $this->stmt->execute(); - - if ( $erg === false ) - { - throw new RuntimeException( 'Could not execute prepared statement "'.$query->query.'": '.implode('/',$this->stmt->errorInfo()) ); - } - - return $this->stmt; - } - - - function fetchRow( $result, $rownum ) - { - $row = $this->stmt->fetch( PDO::FETCH_ASSOC ); - -/* - * - - - if(intval(@$row['id'])==1) - { - echo "Hallo:"; - -// echo "\n";print_r($row)."\n"; - var_dump($row); - echo " ist... ".gettype($row); - - } - - */ - - - if ( is_array($row) && $this->lowercase ) - $row = array_change_key_case($row); - - return $row; - } - - - function freeResult($result) - { - return true; - } - - - function prepare( $query,$param) - { - $this->params = $param; - $offset = 0; - foreach( $param as $name=>$pos) - { - $name = ':'.$name; - $pos += $offset; - $query = substr($query,0,$pos).$name.substr($query,$pos); - - $offset = $offset + strlen($name); - } - - Logger::debug('PDO: SQL-before-preparation: '.$query); - - $this->stmt = $this->connection->prepare($query); - - if ( $this->stmt === false ) - throw new OpenRatException('ERROR_DATABASE_CONNECTION','Could not prepare statement: '.$query.' Cause: '.implode('/',$this->connection->errorInfo()) ); - - } - - - - function bind( $param,$value ) - { - $name = ':'.$param; - - if ( is_string($value) ) - $type = PDO::PARAM_STR; - elseif( is_int($value)) - $type = PDO::PARAM_INT; - elseif( is_null($value)) - $type = PDO::PARAM_NULL; - else - throw new RuntimeException( 'Unknown type' ); - - $this->stmt->bindValue($name,$value,$type); - - Logger::debug('PDO: SQL-Binding of parameter '.$name); - } - - - - /** - * Startet eine Transaktion. - */ - function start() - { - $this->connection->beginTransaction(); - } - - - - /** - * Beendet eine Transaktion. - */ - function commit() - { - $this->connection->commit(); - } - - - /** - * Bricht eine Transaktion ab. - */ - function rollback() - { - try - { - $this->connection->rollBack(); - } - catch ( PDOException $e ) - { - // Kommt vor, wenn keine Transaktion existiert. - } - } - - - - /** - * Setzt die letzte Abfrage zurueck. - */ - function clear() - { - $this->params = array(); - } - - - /** - * Why this? See http://e-mats.org/2008/07/fatal-error-exception-thrown-without-a-stack-frame-in-unknown-on-line-0/ - * - * @return array - */ - function __sleep() { - return array(); - } - -} - -?>- \ No newline at end of file diff --git a/modules/database/require.php b/modules/database/require.php @@ -1,10 +1,12 @@ <?php -include( dirname(__FILE__) . "/Database.class.php" ); -include( dirname(__FILE__) . "/Statement.class.php" ); -include( dirname(__FILE__) . "/Sql.class.php" ); +include( __DIR__ ."/Database.class.php" ); +include( __DIR__. "/Statement.class.php" ); +include( __DIR__ ."/Sql.class.php" ); +include( __DIR__ ."/DbVersion.class.php" ); +// PDO is available since PHP 5.1 if (version_compare(PHP_VERSION, '5.1.0', '>')) - include( dirname(__FILE__) . "/driver/pdo.class.php" ); + include(__DIR__ . "/driver/PDODriver.class.php"); ?> \ No newline at end of file