openrat-cms

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

commit 021ee8111ae1feac267cde808c35a06b435e8806
parent eb3638dcd7f668edf0c1c71339d517c980e9663d
Author: Jan Dankert <devnull@localhost>
Date:   Tue,  3 Jan 2017 22:16:13 +0100

Datenbanktreiberklassen wandern in den Ordner /db/driver

Diffstat:
db/driver/mysql.class.php | 162+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
db/driver/mysqli.class.php | 249+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
db/driver/pdo.class.php | 216+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
db/driver/postgresql.class.php | 262+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
db/driver/sqlite.class.php | 143+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
db/driver/sqlite3.class.php | 151++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
db/mysql.class.php | 162-------------------------------------------------------------------------------
db/mysqli.class.php | 269-------------------------------------------------------------------------------
db/pdo.class.php | 216-------------------------------------------------------------------------------
db/postgresql.class.php | 263-------------------------------------------------------------------------------
db/sqlite.class.php | 143-------------------------------------------------------------------------------
db/sqlite3.class.php | 151------------------------------------------------------------------------------
12 files changed, 1183 insertions(+), 1204 deletions(-)

diff --git a/db/driver/mysql.class.php b/db/driver/mysql.class.php @@ -0,0 +1,161 @@ +<?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 @@ -0,0 +1,248 @@ +<?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/pdo.class.php b/db/driver/pdo.class.php @@ -0,0 +1,215 @@ +<?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 $prepared = false; + + var $lowercase = false; + + + 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 ( substr($c,0,7) == 'option_' ) + $options[substr($c,8)] = $conf[$c]; + + $this->connection = new PDO($url, $user, $pw, $options); + + if ( !is_object($this->connection) ) + { + $this->error = "Could not connect to database on host $host. ".PDO::errorInfo(); + return false; + } + + return true; + } + + + + function disconnect() + { + $this->connection = null; + return true; + } + + + + function query($query) + { + if ( $this->prepared ) + { + $ar = array(); + + foreach( $query->data as $val ) + $ar[] = $val['value']; + $erg = $this->stmt->execute( $ar ); + + if ( $erg === false ) + { + die( 'Could not execute prepared statement "'.$query->query.'" with values "'.implode(',',$ar).'": '.implode('/',$this->connection->errorInfo()) ); + } + + return $this->stmt; + } + else + { + $this->result = $this->connection->query($query); + + if ( ! $this->result ) + { + $this->error = 'Database error: '.implode('/',$this->connection->errorInfo()); + return FALSE; + } + return $this->result; + } + } + + + function fetchRow( $result, $rownum ) + { + if ( $this->prepared ) + $row = $this->stmt->fetch( PDO::FETCH_ASSOC ); + else + $row = $this->result->fetch( PDO::FETCH_ASSOC ); + + if ( is_array($row) && $this->lowercase ) + $row = array_change_key_case($row); + + return $row; + } + + + function freeResult($result) + { + return true; + } + + + function prepare( $query,$param) + { + $offset = 0; + foreach( $param as $pos) + { + foreach( $pos as $posx ) + { + $posx += $offset++; + $query = substr($query,0,$posx).'?'.substr($query,$posx); + } + } + + $this->prepared = true; + $this->stmt = $this->connection->prepare($query); + + if ( $this->stmt === false ) + die( 'Database error: '.implode('/',$this->connection->errorInfo()) ); + + } + + + + function bind( $param,$value ) + { + $this->params[$param] = &$value; + } + + + + /** + * Startet eine Transaktion. + */ + function start() + { + $this->connection->beginTransaction(); + } + + + + /** + * Beendet eine Transaktion. + */ + function commit() + { + $this->connection->commit(); + } + + + /** + * Bricht eine Transaktion ab. + */ + function rollback() + { + $this->connection->rollBack(); + } + + + + /** + * Setzt die letzte Abfrage zurueck. + */ + function clear() + { + $this->prepared = false; + $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/db/driver/postgresql.class.php b/db/driver/postgresql.class.php @@ -0,0 +1,261 @@ +<?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 @@ -0,0 +1,142 @@ +<?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 @@ -0,0 +1,150 @@ +<?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 diff --git a/db/mysql.class.php b/db/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/mysqli.class.php b/db/mysqli.class.php @@ -1,268 +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(); - - #print_r($this->connection); - - if ( false && !is_object($this->connection) ) - { - $this->error = "Could not connect to mysqli-database on host $host."; - return false; - } - - if ( $db != '' ) - { - if ( !mysqli_select_db( $this->connection,$db ) ) - { - $this->error = "Could not select database '$db' on host $host."; - return false; - } - } - - return true; - } - - - - function disconnect() - { - $ret = mysqli_close( $this->connection ); - $this->connection = null; - return $ret; - } - - - - function query($query) - { - if ( $this->prepared ) - { - $ar = array(); - $ar[-1] = $this->stmt; - $ar[0] = ''; - - 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; - } - - $result = mysqli_query($this->connection,$query); - - if ( ! $result ) - { - $this->error = 'Database error: '.mysql_error(); - return FALSE; - } - - return $result; - } - - - function fetchRow( $result, $rownum ) - { - if ( $this->prepared ) - { - $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; - } - } - else - { - // Plain old flat query - $row = $result->fetch_assoc(); - return $row; - } - } - - - 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); - $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 ) - die( 'Mysql-I is 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/pdo.class.php b/db/pdo.class.php @@ -1,215 +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 $prepared = false; - - var $lowercase = false; - - - 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 ( substr($c,0,7) == 'option_' ) - $options[substr($c,8)] = $conf[$c]; - - $this->connection = new PDO($url, $user, $pw, $options); - - if ( !is_object($this->connection) ) - { - $this->error = "Could not connect to database on host $host. ".PDO::errorInfo(); - return false; - } - - return true; - } - - - - function disconnect() - { - $this->connection = null; - return true; - } - - - - function query($query) - { - if ( $this->prepared ) - { - $ar = array(); - - foreach( $query->data as $val ) - $ar[] = $val['value']; - $erg = $this->stmt->execute( $ar ); - - if ( $erg === false ) - { - die( 'Could not execute prepared statement "'.$query->query.'" with values "'.implode(',',$ar).'": '.implode('/',$this->connection->errorInfo()) ); - } - - return $this->stmt; - } - else - { - $this->result = $this->connection->query($query); - - if ( ! $this->result ) - { - $this->error = 'Database error: '.implode('/',$this->connection->errorInfo()); - return FALSE; - } - return $this->result; - } - } - - - function fetchRow( $result, $rownum ) - { - if ( $this->prepared ) - $row = $this->stmt->fetch( PDO::FETCH_ASSOC ); - else - $row = $this->result->fetch( PDO::FETCH_ASSOC ); - - if ( is_array($row) && $this->lowercase ) - $row = array_change_key_case($row); - - return $row; - } - - - function freeResult($result) - { - return true; - } - - - function prepare( $query,$param) - { - $offset = 0; - foreach( $param as $pos) - { - foreach( $pos as $posx ) - { - $posx += $offset++; - $query = substr($query,0,$posx).'?'.substr($query,$posx); - } - } - - $this->prepared = true; - $this->stmt = $this->connection->prepare($query); - - if ( $this->stmt === false ) - die( 'Database error: '.implode('/',$this->connection->errorInfo()) ); - - } - - - - function bind( $param,$value ) - { - $this->params[$param] = $value; - } - - - - /** - * Startet eine Transaktion. - */ - function start() - { - $this->connection->beginTransaction(); - } - - - - /** - * Beendet eine Transaktion. - */ - function commit() - { - $this->connection->commit(); - } - - - /** - * Bricht eine Transaktion ab. - */ - function rollback() - { - $this->connection->rollBack(); - } - - - - /** - * Setzt die letzte Abfrage zurueck. - */ - function clear() - { - $this->prepared = false; - $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/db/postgresql.class.php b/db/postgresql.class.php @@ -1,262 +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: - die('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 ) - { - $this->error = 'PostgreSQL is unable to prepare the statement: '.@pg_errormessage(); - return FALSE; - } - 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/sqlite.class.php b/db/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/sqlite3.class.php b/db/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