openrat-cms

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

commit 5a20dc8da985332b45e734c939ad532d65869ca8
parent 5bfe441eba2b4efc241aafdaab89d1ba22ccfb45
Author: Jan Dankert <devnull@localhost>
Date:   Fri,  6 Jan 2017 22:55:38 +0100

Datenbank-Refactoring: Es wird nur noch der PDO-Treiber unterstützt. Der Rest (MySql, MySql-Improved, SQLite, Postgresql) wird daher gelöscht.

Diffstat:
db/driver/mysql.class.php | 162-------------------------------------------------------------------------------
db/driver/mysqli.class.php | 249-------------------------------------------------------------------------------
db/driver/postgresql.class.php | 262-------------------------------------------------------------------------------
db/driver/sqlite.class.php | 143-------------------------------------------------------------------------------
db/driver/sqlite3.class.php | 151------------------------------------------------------------------------------
5 files changed, 0 insertions(+), 967 deletions(-)

diff --git a/db/driver/mysql.class.php b/db/driver/mysql.class.php @@ -1,161 +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 MySQL - * @author $Author: dankert $ - * @version $Revision: 1.5 $ - * @package openrat.database - */ -class DB_mysql -{ - /** - * Die MySql-Verbindung. - * - * @var Resource - */ - var $connection; - - /** - * Datenbank-Fehler. - * - * @var String - */ - var $error; - - - function connect( $conf ) - { - $host = $conf['host']; - $user = $conf['user']; - $pw = $conf['password']; - $db = $conf['database']; - - if ( !empty($conf['port']) ) - $host .= ':'.$conf['port']; - - if ( $conf['persistent'] ) - $connect_function = 'mysql_pconnect'; - else - $connect_function = 'mysql_connect'; - - if ( $pw != '' ) - $this->connection = $connect_function( $host,$user,$pw ); - elseif ( $user != '' ) - $this->connection = $connect_function( $host,$user ); - elseif ( $host != '' ) - $this->connection = $connect_function( $host ); - else - $this->connection = $connect_function(); - - if ( !is_resource($this->connection) ) - { - $this->error = "Could not connect to database on host $host."; - return false; - } - - if ( $db != '' ) - { - if ( !@mysql_select_db( $db,$this->connection ) ) - { - $this->error = "Could not select database '$db' on host $host."; - return false; - } - } - - // Falls es sich um eine UTF-8-Datenbank handelt, dann setzen wir - // hier explizit den Zeichensatz für alle Anfragen. - $dbCharset = $conf['charset']; - if ( empty($dbCharset) || $dbCharset == 'UTF-8' ) - @mysql_query("SET NAMES 'utf8';",$this->connection); - - - return true; - } - - - - function disconnect() - { - $ret = mysql_close( $this->connection ); - $this->connection = null; - return $ret; - } - - - - function query($query) - { - $result = mysql_query($query, $this->connection); - - if ( ! $result ) - { - $this->error = 'Database error: '.mysql_error(); - return FALSE; - } - - return $result; - } - - - function fetchRow( $result, $rownum ) - { - return mysql_fetch_array( $result,MYSQL_ASSOC ); - } - - - function freeResult($result) - { - if ( is_resource($result) ) - return mysql_free_result($result); - return true; - } - - - /** - * Startet eine Transaktion. - */ - function start() - { - mysql_query('BEGIN', $this->connection); - } - - - /** - * Beendet eine Transaktion. - */ - function commit() - { - mysql_query('COMMIT', $this->connection); - } - - - /** - * Bricht eine Transaktion ab. - */ - function rollback() - { - mysql_query('ROLLBACK', $this->connection); - } - -} - -?>- \ No newline at end of file diff --git a/db/driver/mysqli.class.php b/db/driver/mysqli.class.php @@ -1,248 +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 MySQL - * @author $Author: dankert $ - * @version $Revision: 1.5 $ - * @package openrat.database - */ -class DB_mysqli -{ - /** - * Die MySql-Verbindung. - * - * @var Resource - */ - var $connection; - - /** - * Datenbank-Fehler. - * - * @var String - */ - var $error; - - /** - * SQL-Statement (nur fuer prepared-Statements). - * @var Resource - */ - var $stmt; - - var $prepared = false; - var $params = array(); - - - function connect( $conf ) - { - $host = $conf['host']; - $user = $conf['user']; - $pw = $conf['password']; - $db = $conf['database']; - $host = '127.0.0.1'; - - if ( !empty($conf['port']) ) - $host .= ':'.$conf['port']; - - // 5.3.0 - Added the ability of persistent connections. - if ( $conf['persistent'] && version_compare(PHP_VERSION, '5.3.0', '>') ) - $host = 'p:'.$host; // Prepending host by p: opens a persistent connection. - - $connect_function = 'mysqli_connect'; - - if ( $pw != '' ) - $this->connection = $connect_function( $host,$user,$pw ); - elseif ( $user != '' ) - $this->connection = $connect_function( $host,$user ); - elseif ( $host != '' ) - $this->connection = $connect_function( $host ); - else - $this->connection = $connect_function(); - - if ( !$this->connection ) - { - throw new OpenRatException( 'ERROR_DATABASE_CONNECTION',"Could not connect to database on host $host: ".mysqli_connect_errno().'/'.mysqli_connect_error() ); - } - - if ( $db != '' ) - { - if ( !mysqli_select_db( $this->connection,$db ) ) - { - throw new OpenRatException( 'ERROR_DATABASE_CONNECTION',"Could not select database $db: ".mysqli_error($this->connection) ); - } - } - - return true; - } - - - - function disconnect() - { - $ret = mysqli_close( $this->connection ); - $this->connection = null; - return $ret; - } - - - - function query( &$query ) - { - $ar = array(); - $ar[-1] = $this->stmt; - $ar[0] = ''; - - if ( ! empty($this->params) ) - { - foreach($this->params as $name => $data) - { - switch( $data['type'] ) - { - case 'int': - $ar[0] .= 'i'; - break; - case 'string': - $ar[0] .= 's'; - break; - default: - die('mysqli: unknown data type: '.$data['type']); - } - - $ar[] = &$data['value']; - } - - call_user_func_array('mysqli_stmt_bind_param',$ar); - } - - $this->stmt->execute(); - - return $this->stmt; - } - - - function fetchRow( $result, $rownum ) - { - $result = $this->stmt->result_metadata(); - $fields = array(); - while ($field = mysqli_fetch_field($result)) { - $name = $field->name; - $fields[$name] = &$$name; - } - array_unshift($fields, $this->stmt); - call_user_func_array('mysqli_stmt_bind_result', $fields); - - array_shift($fields); - if ( mysqli_stmt_fetch($this->stmt) ) - { - $temp = array(); - foreach($fields as $key => $val) - $temp[$key] = $val; - //array_push($results, $temp); - return $temp; - } - else - { - mysqli_stmt_close($this->stmt); - $this->stmt = null; - return false; - } - } - - - function freeResult($result) - { - if ( is_resource($result) ) - return mysqli_free_result($result); - return true; - } - - - - function prepare( $query,$param) - { - if ( is_object($this->stmt) ) - { - mysqli_stmt_close($this->stmt); - unset($this->stmt); - $this->stmt = null; - } - - $offset = 0; - foreach( $param as $pos) - { - foreach( $pos as $posn ) - { - $posn += $offset++; - $query = substr($query,0,$posn).'?'.substr($query,$posn); - } - } - - $this->stmt = mysqli_prepare($this->connection,$query); - if ( $this->stmt === FALSE ) - throw new OpenRatException( 'ERROR_DATABASE','Unable to prepare the statement: '.$query.' : '.mysqli_error($this->connection) ); - $this->prepared = true; - } - - function bind( $param,&$value ) - { - $this->params[$param] = $value; - } - - - /** - * Startet eine Transaktion. - */ - function start() - { - mysqli_query($this->connection,'BEGIN'); - } - - - /** - * Beendet eine Transaktion. - */ - function commit() - { - mysqli_query($this->connection,'COMMIT'); - } - - - /** - * Bricht eine Transaktion ab. - */ - function rollback() - { - mysqli_query($this->connection,'ROLLBACK'); - } - - - /** - * Setzt die letzte Abfrage zurueck. - */ - function clear() - { - $this->prepared = false; - $this->params = array(); - } - -} - -?>- \ No newline at end of file diff --git a/db/driver/postgresql.class.php b/db/driver/postgresql.class.php @@ -1,261 +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 PostgreSQL - * @author $Author: dankert $ - * @version $Revision: 1.5 $ - * @package openrat.database - */ -class DB_postgresql -{ - var $connection; - - /** - * SQL-Statement (nur fuer prepared-Statements). - * @var Resource - */ - var $prepared; - - var $params = array(); - - - /** - * Verbinden zum POSTGRES-Server. - * - * @param Array $conf - * @return boolean 'true', wenn Verbindung aufgebaut wurde - */ - function connect( $conf ) - { - $host = $conf['host']; - $user = $conf['user']; - $pw = $conf['password']; - $db = $conf['database']; - - if ( !empty($conf['port']) ) - $host .= ':'.$conf['port']; - - if ( $conf['persistent'] ) - $connect_function = 'pg_pconnect'; - else - $connect_function = 'pg_connect'; - - if ( ! function_exists($connect_function)) - { - $this->error = 'Function does not exist: '.$connect_function.' Postgresql is not available'; - return false; - } - - Logger::debug('postgresql: connecting to: '."host=$host, dbname=$db"); - - if ( $pw != '' ) - $this->connection = @$connect_function( "host=$host dbname=$db user=$user password=$pw" ); - elseif ( $user != '' ) - $this->connection = @$connect_function( "host=$host dbname=$db user=$user" ); - elseif ( $host != '' ) - $this->connection = @$connect_function( "host=$host dbname=$db" ); - else - $this->connection = @$connect_function( "dbname=$db"); - - if ( ! is_resource($this->connection) ) - { - $this->error = 'Could not connect to postgresql-server '.$host.': '.@pg_errormessage(); - return false; - } - - return true; - } - - - - /** - * Verbindung schliessen. - * - * @return unknown - */ - function disconnect() - { - $ret = pg_query( $this->connection ); - $this->connection = null; - return $ret; - } - - - - /** - * Startet eine Transaktion. - */ - function start() - { - @pg_exec( $this->connection,"BEGIN WORK" ); - } - - - /** - * Beendet eine Transaktion. - */ - function commit() - { - @pg_exec( $this->connection,"COMMIT" ); - } - - - /** - * Bricht eine Transaktion ab. - */ - function rollback() - { - @pg_exec( $this->connection,"ROLLBACK" ); - } - - - - function query($query) - { - if ( $this->prepared ) - { - // Prepared Statement - $ar = array(); - foreach($this->params as $name => $data) - { - switch( $data['type'] ) - { - case 'string': - $ar[] = (String)$data['value']; - break; - case 'int': - $ar[] = (int) $data['value']; - break; - case 'null': - $ar[] = null; - break; - default: - throw new RuntimeException('unknown type "'.$data['type'].'"'); - } - } - - $result = @pg_execute( $this->connection,$this->stmtid,$ar ); - - if ( $result === false ) - { - if ( empty($this->error) ) - $this->error = 'PostgreSQL is unable to execute the prepared statement: '.@pg_errormessage(); - return FALSE; - } - - return $result; - } - else - { - // Flat Query: - $result = @pg_exec( $this->connection,$query ); - - if ( ! $result ) - { - if ( empty($this->error) ) - $this->error = 'PostgreSQL is unable to execute the flat query: '.@pg_errormessage(); - return FALSE; - } - - return $result; - } - } - - - function fetchRow( $result, $rownum ) - { - if ( $rownum >= pg_num_rows($result) ) - return false; - - return pg_fetch_array( $result,$rownum,PGSQL_ASSOC ); - } - - - function freeResult($result) - { - return pg_freeresult($result); - } - - - function prepare( $query,$param ) - { - $nr = 1; - foreach($param as $name=>$unused_a ) - { - foreach( $param[$name] as $idx=>$xyz ) - { - $pos = $param[$name][$idx]; - - $query = substr( $query,0,$pos ).'$'.$nr.substr( $query,$pos ); - - foreach( $param as $pn=>$par) - { - foreach( $par as $i=>$p ) - { - if ( $p > $pos ) - $param[$pn][$i]=$p+strlen((string)$nr)+1; - } - } - } - $nr++; - } - $this->stmtid = md5($query); - $this->prepared = true; - - // Feststellen, ob Statement bereits vorhanden ist - $result = pg_query_params($this->connection, 'SELECT name FROM pg_prepared_statements WHERE name = $1', array($this->stmtid)); - if (pg_num_rows($result) > 0) - return; - - $erg = @pg_prepare($this->connection,$this->stmtid,$query); - - if ( $erg === FALSE ) - { - throw new OpenRatException('ERROR_DATABASE','PostgreSQL is unable to prepare the statement: "'.$query.'" Reason: '.@pg_errormessage() ); - } - else - { - return $erg; - } - } - - - function bind( $param,$value ) - { - $this->params[$param] = &$value; - } - - - function clear() - { - $this->prepared = false; - $this->params = array(); - } - - function escape() - { - return 'pg_escape_string'; - } - -} - -?>- \ No newline at end of file diff --git a/db/driver/sqlite.class.php b/db/driver/sqlite.class.php @@ -1,142 +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 SQ-Lite-Datenbanken - * @author $Author: dankert $ - * @version $Revision: 1.5 $ - * @package openrat.database - */ -class DB_sqlite -{ - /** - * Die SQ-Lite-Verbindung. - * - * @var Resource - */ - var $connection; - - /** - * Datenbank-Fehler. - * - * @var String - */ - var $error; - - - function connect( $conf ) - { - $filename = $conf['filename']; - - if ( $conf['persistent'] ) - $connect_function = 'sqlite_popen'; - else - $connect_function = 'sqlite_open'; - - if ( ! function_exists($connect_function)) - { - $this->error = 'Function does not exist: '.$connect_function.' SQlite is not available'; - return false; - } - - $this->connection = @$connect_function($filename,0666,$error); - - if ( !is_resource($this->connection) ) - { - $this->error = 'Could not connect to sqlite-database: '.$error; - return false; - } - - return true; - } - - - - function disconnect() - { - $ret = sqlite_close( $this->connection ); - $this->connection = null; - return $ret; - } - - - - function query($query) - { - $result = sqlite_query($this->connection,$query ); - - if ( ! $result ) - { - $this->error = 'Database error: '.sqlite_error_string(sqlite_last_error($this->connection)); - return FALSE; - } - - return $result; - } - - /** - * Startet eine Transaktion. - */ - function start() - { - sqlite_query( $this->connection,'BEGIN TRANSACTION;'); - } - - - /** - * Beendet eine Transaktion. - */ - function commit() - { - sqlite_query( $this->connection,'COMMIT;'); - } - - - /** - * Bricht eine Transaktion ab. - */ - function rollback() - { - sqlite_query( $this->connection,'ROLLBACK;'); - } - - - - function fetchRow( $result, $rownum ) - { - return sqlite_fetch_array( $result,SQLITE_ASSOC ); - } - - - function freeResult($result) - { - return true; - } - - - function escape() - { - return 'sqlite_escape_string'; - } -} - - -?>- \ No newline at end of file diff --git a/db/driver/sqlite3.class.php b/db/driver/sqlite3.class.php @@ -1,150 +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 SQLITE3 - * @author $Author: dankert $ - * @version $Revision: 1.5 $ - * @package openrat.database - */ -class DB_sqlite3 -{ - /** - * Das SQLITE3-Verbindungsobjekt. - * - * @var Resource - */ - var $connection; - - /** - * Datenbank-Fehler. - * - * @var String - */ - var $error; - - - function connect( $conf ) - { - $filename = $conf['filename']; - - $this->connection = new SQLite3( $filename ); - - if ( !is_object($this->connection) ) - { - $this->error = "Could not connect to SQLITE3-database: ".SQLite3::lastErrorMsg(); - return false; - } - - return true; - } - - - - function disconnect() - { - $this->connection->close(); - $this->connection = null; - return true; - } - - - - function query($query) - { - $this->result = $this->connection->query($query); - - if ( !$this->result ) - { - $this->error = 'Database error: '.$this->connection->lastErrorMsg(); - return FALSE; - } - - return $this->result; - } - - - function fetchRow( $result, $rownum ) - { - return $this->result->fetchArray( SQLITE3_ASSOC ); - } - - - function freeResult($result) - { - return true; - } - - - - /** - * Startet eine Transaktion. - */ - function start() - { - $this->connection->query( 'BEGIN TRANSACTION;'); - } - - - /** - * Beendet eine Transaktion. - */ - function commit() - { - $this->connection->query( 'COMMIT;'); - } - - - /** - * Bricht eine Transaktion ab. - */ - function rollback() - { - $this->connection->query( 'ROLLBACK;'); - } - - - function prepare( $query,$param) - { - foreach( $param as $pos) - { - foreach( $pos as $pos ) - { - $query = substr($query,0,$pos-1).'?'.substr($query,$pos+1); - } - } - - $this->stmt = $this->connection->prepare($query); - - } - - function bind( $param,$value ) - { - $this->params[$param] = $value; - } - - function clear() - { - $this->params = array(); - } -} - -?>- \ No newline at end of file