From 9ff43d0ac3ad9f614831b5de4509d6e73580f279 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 10 Nov 2007 07:37:44 +0000 Subject: [PATCH] added DibiDriver::disconnect() --- dibi/dibi.php | 32 ++++++++++++--- dibi/drivers/mssql.php | 23 ++++++++--- dibi/drivers/mysql.php | 23 ++++++++--- dibi/drivers/mysqli.php | 23 ++++++++--- dibi/drivers/odbc.php | 32 +++++++-------- dibi/drivers/oracle.php | 21 +++++++--- dibi/drivers/pdo.php | 23 +++++++---- dibi/drivers/postgre.php | 46 +++++++++++----------- dibi/drivers/sqlite.php | 30 +++++++++----- dibi/libs/DibiDriver.php | 74 +++++++++++++++++++++++++++++------ dibi/libs/NObject.php | 55 +++++++++++++------------- examples/connect.php | 20 +++++++++- examples/extension.method.php | 27 +++++++++++++ icons/example.html | 2 +- version.txt | 2 +- 15 files changed, 304 insertions(+), 129 deletions(-) create mode 100644 examples/extension.method.php diff --git a/dibi/dibi.php b/dibi/dibi.php index bea673b5..349a9c8a 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -14,7 +14,7 @@ * @author David Grudl * @copyright Copyright (c) 2005, 2007 David Grudl * @license http://php7.org/dibi/license (dibi license) - * @version 0.9b (Revision: $WCREV$, Date: $WCDATE$) + * @version 0.9 (Revision: $WCREV$, Date: $WCDATE$) * @category Database * @package Dibi * @link http://php7.org/dibi/ @@ -90,7 +90,7 @@ class dibi FIELD_COUNTER = 'c', // counter or autoincrement, is integer // dibi version - VERSION = '0.9b (Revision: $WCREV$, Date: $WCDATE$)'; + VERSION = '0.9 (Revision: $WCREV$, Date: $WCDATE$)'; /** @@ -198,6 +198,18 @@ class dibi + /** + * Disconnects from database (doesn't destroy DibiDriver object) + * + * @return void + */ + public static function disconnect() + { + self::getConnection()->disconnect(); + } + + + /** * Returns TRUE when connection was established * @@ -254,7 +266,7 @@ class dibi * Generates and executes SQL query - Monostate for DibiDriver::query() * * @param array|mixed one or more arguments - * @return DibiResult|TRUE + * @return DibiResult Result set object (if any) * @throws DibiException */ public static function query($args) @@ -269,8 +281,8 @@ class dibi /** * Executes the SQL query - Monostate for DibiDriver::nativeQuery() * - * @param string SQL statement. - * @return DibiResult|TRUE + * @param string SQL statement. + * @return DibiResult Result set object (if any) */ public static function nativeQuery($sql) { @@ -351,6 +363,16 @@ class dibi + /** + * Experimental; will be used in PHP 5.3 + */ + public static function __callStatic($name, $args) + { + return call_user_func_array(array(self::getConnection(), $name), $args); + } + + + /** * Create a new substitution pair for indentifiers * diff --git a/dibi/drivers/mssql.php b/dibi/drivers/mssql.php index 6600ee74..8c8755e9 100644 --- a/dibi/drivers/mssql.php +++ b/dibi/drivers/mssql.php @@ -25,7 +25,7 @@ * * @version $Revision$ $Date$ */ -class DibiMsSqlDriver extends DibiDriver +final class DibiMsSqlDriver extends DibiDriver { /** * Describes how convert some datatypes to SQL command @@ -61,7 +61,7 @@ class DibiMsSqlDriver extends DibiDriver * @throws DibiException * @return resource */ - protected function connect() + protected function doConnect() { if (!extension_loaded('mssql')) { throw new DibiException("PHP extension 'mssql' is not loaded"); @@ -83,17 +83,28 @@ class DibiMsSqlDriver extends DibiDriver throw new DibiDatabaseException("Can't select DB '$config[database]'"); } - dibi::notify('connected', $this); return $connection; } + /** + * Disconnects from a database + * + * @return void + */ + protected function doDisconnect() + { + mssql_close($this->getConnection()); + } + + + /** * Internal: Executes the SQL query * * @param string SQL statement. - * @return DibiResult|TRUE Result set object + * @return DibiResult Result set object * @throws DibiDatabaseException */ protected function doQuery($sql) @@ -104,7 +115,7 @@ class DibiMsSqlDriver extends DibiDriver throw new DibiDatabaseException('Query error', 0, $sql); } - return is_resource($res) ? new DibiMSSqlResult($res) : TRUE; + return is_resource($res) ? new DibiMSSqlResult($res) : NULL; } @@ -258,7 +269,7 @@ class DibiMsSqlDriver extends DibiDriver -class DibiMSSqlResult extends DibiResult +final class DibiMSSqlResult extends DibiResult { /** diff --git a/dibi/drivers/mysql.php b/dibi/drivers/mysql.php index 2e419982..0367512a 100644 --- a/dibi/drivers/mysql.php +++ b/dibi/drivers/mysql.php @@ -25,7 +25,7 @@ * * @version $Revision$ $Date$ */ -class DibiMySqlDriver extends DibiDriver +final class DibiMySqlDriver extends DibiDriver { /** * Describes how convert some datatypes to SQL command @@ -70,7 +70,7 @@ class DibiMySqlDriver extends DibiDriver * @throws DibiException * @return resource */ - protected function connect() + protected function doConnect() { if (!extension_loaded('mysql')) { throw new DibiException("PHP extension 'mysql' is not loaded"); @@ -116,17 +116,28 @@ class DibiMySqlDriver extends DibiDriver throw new DibiDatabaseException(mysql_error($connection), mysql_errno($connection)); } - dibi::notify('connected', $this); return $connection; } + /** + * Disconnects from a database + * + * @return void + */ + protected function doDisconnect() + { + mysql_close($this->getConnection()); + } + + + /** * Internal: Executes the SQL query * * @param string SQL statement. - * @return DibiResult|TRUE Result set object + * @return DibiResult Result set object * @throws DibiDatabaseException */ protected function doQuery($sql) @@ -138,7 +149,7 @@ class DibiMySqlDriver extends DibiDriver throw new DibiDatabaseException(mysql_error($connection), $errno, $sql); } - return is_resource($res) ? new DibiMySqlResult($res) : TRUE; + return is_resource($res) ? new DibiMySqlResult($res) : NULL; } @@ -291,7 +302,7 @@ class DibiMySqlDriver extends DibiDriver -class DibiMySqlResult extends DibiResult +final class DibiMySqlResult extends DibiResult { /** diff --git a/dibi/drivers/mysqli.php b/dibi/drivers/mysqli.php index 92cf9386..275995f0 100644 --- a/dibi/drivers/mysqli.php +++ b/dibi/drivers/mysqli.php @@ -25,7 +25,7 @@ * * @version $Revision$ $Date$ */ -class DibiMySqliDriver extends DibiDriver +final class DibiMySqliDriver extends DibiDriver { /** * Describes how convert some datatypes to SQL command @@ -71,7 +71,7 @@ class DibiMySqliDriver extends DibiDriver * @throws DibiException * @return resource */ - protected function connect() + protected function doConnect() { if (!extension_loaded('mysqli')) { throw new DibiException("PHP extension 'mysqli' is not loaded"); @@ -89,17 +89,28 @@ class DibiMySqliDriver extends DibiDriver mysqli_query($connection, "SET NAMES '" . $config['charset'] . "'"); } - dibi::notify('connected', $this); return $connection; } + /** + * Disconnects from a database + * + * @return void + */ + protected function doDisconnect() + { + mysqli_close($this->getConnection()); + } + + + /** * Internal: Executes the SQL query * * @param string SQL statement. - * @return DibiResult|TRUE Result set object + * @return DibiResult Result set object * @throws DibiDatabaseException */ protected function doQuery($sql) @@ -111,7 +122,7 @@ class DibiMySqliDriver extends DibiDriver throw new DibiDatabaseException(mysqli_error($connection), $errno, $sql); } - return is_object($res) ? new DibiMySqliResult($res) : TRUE; + return is_object($res) ? new DibiMySqliResult($res) : NULL; } @@ -275,7 +286,7 @@ class DibiMySqliDriver extends DibiDriver -class DibiMySqliResult extends DibiResult +final class DibiMySqliResult extends DibiResult { /** diff --git a/dibi/drivers/odbc.php b/dibi/drivers/odbc.php index ce629f04..6a72efb0 100644 --- a/dibi/drivers/odbc.php +++ b/dibi/drivers/odbc.php @@ -25,7 +25,7 @@ * * @version $Revision$ $Date$ */ -class DibiOdbcDriver extends DibiDriver +final class DibiOdbcDriver extends DibiDriver { /** * Describes how convert some datatypes to SQL command @@ -74,7 +74,7 @@ class DibiOdbcDriver extends DibiDriver * @throws DibiException * @return resource */ - protected function connect() + protected function doConnect() { if (!extension_loaded('odbc')) { throw new DibiException("PHP extension 'odbc' is not loaded"); @@ -92,28 +92,19 @@ class DibiOdbcDriver extends DibiDriver throw new DibiDatabaseException(odbc_errormsg(), odbc_error()); } - dibi::notify('connected', $this); return $connection; } /** - * Executes the SQL query + * Disconnects from a database * - * @param string SQL statement. - * @return DibiResult|TRUE Result set object - * @throws DibiException + * @return void */ - public function nativeQuery($sql) + protected function doDisconnect() { - $this->affectedRows = FALSE; - $res = parent::nativeQuery($sql); - if ($res instanceof DibiResult) { - $this->affectedRows = odbc_num_rows($res->getResource()); - if ($this->affectedRows < 0) $this->affectedRows = FALSE; - } - return $res; + odbc_close($this->getConnection()); } @@ -122,11 +113,12 @@ class DibiOdbcDriver extends DibiDriver * Internal: Executes the SQL query * * @param string SQL statement. - * @return DibiResult|TRUE Result set object + * @return DibiResult Result set object * @throws DibiDatabaseException */ protected function doQuery($sql) { + $this->affectedRows = FALSE; $connection = $this->getConnection(); $res = @odbc_exec($connection, $sql); @@ -134,7 +126,11 @@ class DibiOdbcDriver extends DibiDriver throw new DibiDatabaseException(odbc_errormsg($connection), odbc_error($connection), $sql); } - return is_resource($res) ? new DibiOdbcResult($res) : TRUE; + if (is_resource($res)) { + $this->affectedRows = odbc_num_rows($res); + if ($this->affectedRows < 0) $this->affectedRows = FALSE; + return new DibiOdbcResult($res); + } } @@ -295,7 +291,7 @@ class DibiOdbcDriver extends DibiDriver -class DibiOdbcResult extends DibiResult +final class DibiOdbcResult extends DibiResult { private $row = 0; diff --git a/dibi/drivers/oracle.php b/dibi/drivers/oracle.php index 6d21a6fe..280d10e9 100644 --- a/dibi/drivers/oracle.php +++ b/dibi/drivers/oracle.php @@ -25,7 +25,7 @@ * * @version $Revision$ $Date$ */ -class DibiOracleDriver extends DibiDriver +final class DibiOracleDriver extends DibiDriver { /** * Describes how convert some datatypes to SQL command @@ -65,7 +65,7 @@ class DibiOracleDriver extends DibiDriver * @throws DibiException * @return resource */ - protected function connect() + protected function doConnect() { if (!extension_loaded('oci8')) { throw new DibiException("PHP extension 'oci8' is not loaded"); @@ -79,17 +79,28 @@ class DibiOracleDriver extends DibiDriver throw new DibiDatabaseException($err['message'], $err['code']); } - dibi::notify('connected', $this); return $connection; } + /** + * Disconnects from a database + * + * @return void + */ + protected function doDisconnect() + { + oci_close($this->getConnection()); + } + + + /** * Internal: Executes the SQL query * * @param string SQL statement. - * @return DibiResult|TRUE Result set object + * @return DibiResult Result set object * @throws DibiDatabaseException */ protected function doQuery($sql) @@ -260,7 +271,7 @@ class DibiOracleDriver extends DibiDriver -class DibiOracleResult extends DibiResult +final class DibiOracleResult extends DibiResult { /** diff --git a/dibi/drivers/pdo.php b/dibi/drivers/pdo.php index 59cb5fd5..b65c8276 100644 --- a/dibi/drivers/pdo.php +++ b/dibi/drivers/pdo.php @@ -25,7 +25,7 @@ * * @version $Revision$ $Date$ */ -class DibiPdoDriver extends DibiDriver +final class DibiPdoDriver extends DibiDriver { /** * Describes how convert some datatypes to SQL command @@ -61,7 +61,7 @@ class DibiPdoDriver extends DibiDriver * @throws DibiException * @return resource */ - protected function connect() + protected function doConnect() { if (!extension_loaded('pdo')) { throw new DibiException("PHP extension 'pdo' is not loaded"); @@ -70,24 +70,33 @@ class DibiPdoDriver extends DibiDriver $config = $this->getConfig(); $connection = new PDO($config['dsn'], $config['username'], $config['password']); $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - dibi::notify('connected', $this); return $connection; } + /** + * Disconnects from a database + * + * @return void + */ + protected function doDisconnect() + { + } + + + /** * Internal: Executes the SQL query * * @param string SQL statement. - * @return DibiResult|TRUE Result set object + * @return DibiResult Result set object * @throws DibiDatabaseException */ protected function doQuery($sql) { $res = $this->getConnection()->query($sql); - return $res instanceof PDOStatement ? new DibiPdoResult($res) : TRUE; + return $res instanceof PDOStatement ? new DibiPdoResult($res) : NULL; } @@ -235,7 +244,7 @@ class DibiPdoDriver extends DibiDriver -class DibiPdoResult extends DibiResult +final class DibiPdoResult extends DibiResult { private $row = 0; diff --git a/dibi/drivers/postgre.php b/dibi/drivers/postgre.php index 6d4c7702..d38104de 100644 --- a/dibi/drivers/postgre.php +++ b/dibi/drivers/postgre.php @@ -25,7 +25,7 @@ * * @version $Revision$ $Date$ */ -class DibiPostgreDriver extends DibiDriver +final class DibiPostgreDriver extends DibiDriver { /** * Describes how convert some datatypes to SQL command @@ -67,7 +67,7 @@ class DibiPostgreDriver extends DibiDriver * @throws DibiException * @return resource */ - protected function connect() + protected function doConnect() { if (!extension_loaded('pgsql')) { throw new DibiException("PHP extension 'pgsql' is not loaded"); @@ -101,28 +101,19 @@ class DibiPostgreDriver extends DibiDriver // don't handle this error... } - dibi::notify('connected', $this); return $connection; } /** - * Executes the SQL query + * Disconnects from a database * - * @param string SQL statement. - * @return DibiResult|TRUE Result set object - * @throws DibiException + * @return void */ - public function nativeQuery($sql) + protected function doDisconnect() { - $this->affectedRows = FALSE; - $res = parent::nativeQuery($sql); - if ($res instanceof DibiResult) { - $this->affectedRows = pg_affected_rows($res->getResource()); - if ($this->affectedRows < 0) $this->affectedRows = FALSE; - } - return $res; + pg_close($this->getConnection()); } @@ -131,10 +122,11 @@ class DibiPostgreDriver extends DibiDriver * Internal: Executes the SQL query * * @param string SQL statement. - * @return DibiResult|TRUE Result set object + * @param bool update affected rows? + * @return DibiResult Result set object * @throws DibiDatabaseException */ - protected function doQuery($sql) + protected function doQuery($sql, $silent = FALSE) { $connection = $this->getConnection(); $res = @pg_query($connection, $sql); @@ -143,7 +135,13 @@ class DibiPostgreDriver extends DibiDriver throw new DibiDatabaseException(pg_last_error($connection), 0, $sql); } - return is_resource($res) ? new DibiPostgreResult($res) : TRUE; + if (is_resource($res)) { + if (!$silent) { + $this->affectedRows = pg_affected_rows($res); + if ($this->affectedRows < 0) $this->affectedRows = FALSE; + } + return new DibiPostgreResult($res); + } } @@ -169,9 +167,9 @@ class DibiPostgreDriver extends DibiDriver { if ($sequence === NULL) { // PostgreSQL 8.1 is needed - $res = $this->doQuery("SELECT LASTVAL() AS seq"); + $res = $this->doQuery("SELECT LASTVAL() AS seq", TRUE); } else { - $res = $this->doQuery("SELECT CURRVAL('$sequence') AS seq"); + $res = $this->doQuery("SELECT CURRVAL('$sequence') AS seq", TRUE); } if (is_resource($res)) { @@ -191,7 +189,7 @@ class DibiPostgreDriver extends DibiDriver */ public function begin() { - $this->doQuery('BEGIN'); + $this->doQuery('BEGIN', TRUE); dibi::notify('begin', $this); } @@ -203,7 +201,7 @@ class DibiPostgreDriver extends DibiDriver */ public function commit() { - $this->doQuery('COMMIT'); + $this->doQuery('COMMIT', TRUE); dibi::notify('commit', $this); } @@ -215,7 +213,7 @@ class DibiPostgreDriver extends DibiDriver */ public function rollback() { - $this->doQuery('ROLLBACK'); + $this->doQuery('ROLLBACK', TRUE); dibi::notify('rollback', $this); } @@ -306,7 +304,7 @@ class DibiPostgreDriver extends DibiDriver -class DibiPostgreResult extends DibiResult +final class DibiPostgreResult extends DibiResult { /** diff --git a/dibi/drivers/sqlite.php b/dibi/drivers/sqlite.php index c092ebd1..1a41037f 100644 --- a/dibi/drivers/sqlite.php +++ b/dibi/drivers/sqlite.php @@ -25,7 +25,7 @@ * * @version $Revision$ $Date$ */ -class DibiSqliteDriver extends DibiDriver +final class DibiSqliteDriver extends DibiDriver { /** * Describes how convert some datatypes to SQL command @@ -60,7 +60,7 @@ class DibiSqliteDriver extends DibiDriver * @throws DibiException * @return resource */ - protected function connect() + protected function doConnect() { if (!extension_loaded('sqlite')) { throw new DibiException("PHP extension 'sqlite' is not loaded"); @@ -79,29 +79,41 @@ class DibiSqliteDriver extends DibiDriver throw new DibiDatabaseException($errorMsg); } - dibi::notify('connected', $this); return $connection; } + /** + * Disconnects from a database + * + * @return void + */ + protected function doDisconnect() + { + sqlite_close($this->getConnection()); + } + + + /** * Internal: Executes the SQL query * * @param string SQL statement. - * @return DibiResult|TRUE Result set object + * @return DibiResult Result set object * @throws DibiDatabaseException */ protected function doQuery($sql) { $connection = $this->getConnection(); - $res = @sqlite_query($connection, $sql, SQLITE_ASSOC); + $errorMsg = NULL; + $res = @sqlite_query($connection, $sql, SQLITE_ASSOC, $errorMsg); - if ($errno = sqlite_last_error($connection)) { - throw new DibiDatabaseException(sqlite_error_string($errno), $errno, $sql); + if ($errorMsg !== NULL) { + throw new DibiDatabaseException($errorMsg, sqlite_last_error($connection), $sql); } - return is_resource($res) ? new DibiSqliteResult($res) : TRUE; + return is_resource($res) ? new DibiSqliteResult($res) : NULL; } @@ -249,7 +261,7 @@ class DibiSqliteDriver extends DibiDriver -class DibiSqliteResult extends DibiResult +final class DibiSqliteResult extends DibiResult { /** diff --git a/dibi/libs/DibiDriver.php b/dibi/libs/DibiDriver.php index 8e08004e..af452aeb 100644 --- a/dibi/libs/DibiDriver.php +++ b/dibi/libs/DibiDriver.php @@ -64,19 +64,48 @@ abstract class DibiDriver extends NObject $this->config = $config; if (empty($config['lazy'])) { - $this->connection = $this->connect(); + $this->connect(); } } + /** + * Automatically frees the resources allocated for this result set + * + * @return void + */ + public function __destruct() + { + $this->disconnect(); + } + + + /** * Connects to a database * - * @throws DibiException - * @return resource + * @return void */ - abstract protected function connect(); + final public function connect() + { + $this->connection = $this->doConnect(); + dibi::notify('connected'); + } + + + + /** + * Disconnects from a database + * + * @return void + */ + final public function disconnect() + { + $this->doDisconnect(); + $this->connection = NULL; + dibi::notify('disconnected'); + } @@ -110,8 +139,8 @@ abstract class DibiDriver extends NObject */ final public function getConnection() { - if (!$this->connection) { - $this->connection = $this->connect(); + if ($this->connection === NULL) { + $this->connect(); } return $this->connection; @@ -123,7 +152,7 @@ abstract class DibiDriver extends NObject * Generates (translates) and executes SQL query * * @param array|mixed one or more arguments - * @return DibiResult|TRUE + * @return DibiResult Result set object (if any) * @throws DibiException */ final public function query($args) @@ -161,16 +190,17 @@ abstract class DibiDriver extends NObject /** * Executes the SQL query * - * @param string SQL statement. - * @return DibiResult|TRUE Result set object + * @param string SQL statement. + * @return DibiResult Result set object (if any) * @throws DibiException */ - public function nativeQuery($sql) + final public function nativeQuery($sql) { dibi::notify('beforeQuery', $this, $sql); $res = $this->doQuery($sql); dibi::notify('afterQuery', $this, $res); - return $res; + // backward compatibility - will be removed! + return $res instanceof DibiResult ? $res : TRUE; } @@ -197,11 +227,31 @@ abstract class DibiDriver extends NObject + /** + * Internal: Connects to a database + * + * @throws DibiException + * @return resource + */ + abstract protected function doConnect(); + + + + /** + * Internal: Disconnects from a database + * + * @throws DibiException + * @return void + */ + abstract protected function doDisconnect(); + + + /** * Internal: Executes the SQL query * * @param string SQL statement. - * @return DibiResult|TRUE Result set object + * @return DibiResult Result set object * @throws DibiDatabaseException */ abstract protected function doQuery($sql); diff --git a/dibi/libs/NObject.php b/dibi/libs/NObject.php index 61d0cfe8..0fa5ad6e 100644 --- a/dibi/libs/NObject.php +++ b/dibi/libs/NObject.php @@ -1,22 +1,22 @@ newMethod($x); // equivalent to MyClass_prototype_newMethod($obj, $x); * + * + * @author David Grudl + * @copyright Copyright (c) 2004, 2007 David Grudl + * @license http://php7.org/nette/license (Nette license) + * @link http://php7.org/nette/ */ abstract class NObject { @@ -102,6 +107,10 @@ abstract class NObject */ protected function __call($name, $args) { + if ($name === '') { + throw new BadMethodCallException("Call to method without name"); + } + // object prototypes support Class__method() // (or use class Class__method { static function ... } with autoloading?) $cl = $class = get_class($this); @@ -122,12 +131,12 @@ abstract class NObject * * @param string property name * @return mixed property value or the event handler list - * @throws NPropertyException if the property is not defined. + * @throws LogicException if the property is not defined. */ protected function &__get($name) { if ($name === '') { - throw new NPropertyException('Property name must be a non-empty string'); + throw new LogicException("Cannot read an property without name"); } // property getter support @@ -141,7 +150,7 @@ abstract class NObject return $val; } else { - throw new NPropertyException("Cannot read an undeclared property $class::\$$name"); + throw new LogicException("Cannot read an undeclared property $class::\$$name"); } } @@ -153,12 +162,12 @@ abstract class NObject * @param string property name * @param mixed property value * @return void - * @throws NPropertyException if the property is not defined or is read-only + * @throws LogicException if the property is not defined or is read-only */ protected function __set($name, $value) { if ($name === '') { - throw new NPropertyException('Property name must be a non-empty string'); + throw new LogicException('Cannot assign to an property without name'); } // property setter support @@ -169,11 +178,11 @@ abstract class NObject $this->$m($value); } else { - throw new NPropertyException("Cannot assign to a read-only property $class::\$$name"); + throw new LogicException("Cannot assign to a read-only property $class::\$$name"); } } else { - throw new NPropertyException("Cannot assign to an undeclared property $class::\$$name"); + throw new LogicException("Cannot assign to an undeclared property $class::\$$name"); } } @@ -197,12 +206,12 @@ abstract class NObject * * @param string property name * @return void - * @throws NPropertyException + * @throws LogicException */ protected function __unset($name) { $class = get_class($this); - throw new NPropertyException("Cannot unset an declared or undeclared property $class::\$$name"); + throw new LogicException("Cannot unset an property $class::\$$name"); } @@ -227,12 +236,4 @@ abstract class NObject -/** - * Occurs on unsuccessful attempts to get or set the value of a property - */ -class NPropertyException extends Exception -{ } - - -} \ No newline at end of file diff --git a/examples/connect.php b/examples/connect.php index e98a06d4..88eec70b 100644 --- a/examples/connect.php +++ b/examples/connect.php @@ -30,10 +30,10 @@ try { -// connects to MySQL / MySQLi +// connects to MySQLi using array try { dibi::connect(array( - 'driver' => 'mysql', // or 'mysqli' + 'driver' => 'mysqli', 'host' => 'localhost', 'username' => 'root', 'password' => 'xxx', @@ -109,3 +109,19 @@ try { } catch (DibiException $e) { echo '
', $e, '
'; } + + + +// connects to Oracle +try { + dibi::connect(array( + 'driver' => 'oracle', + 'username' => 'root', + 'password' => 'xxx', + 'database' => 'db', + )); + echo '

Connected to Oracle

'; + +} catch (DibiException $e) { + echo '
', $e, '
'; +} diff --git a/examples/extension.method.php b/examples/extension.method.php new file mode 100644 index 00000000..dd0fb7c3 --- /dev/null +++ b/examples/extension.method.php @@ -0,0 +1,27 @@ +

dibi extension method example

+
+ 'sqlite',
+    'database' => 'sample.sdb',
+));
+
+
+
+// using the "prototype" to add custom method to class DibiResult
+function DibiResult_prototype_fetchShuffle(DibiResult $obj)
+{
+    $all = $obj->fetchAll();
+    shuffle($all);
+    return $all;
+}
+
+
+// fetch complete result set shuffled
+$res = dibi::query('SELECT * FROM [customers]');
+$all = $res->fetchShuffle();
+print_r($all);
diff --git a/icons/example.html b/icons/example.html
index c041c841..9ae47d54 100644
--- a/icons/example.html
+++ b/icons/example.html
@@ -1,2 +1,2 @@
-dibi powered
diff --git a/version.txt b/version.txt
index 7b8fa205..a89c6c34 100644
--- a/version.txt
+++ b/version.txt
@@ -1,4 +1,4 @@
-Dibi version 0.9b
+Dibi version 0.9
 
 Revision: $WCREV$
 Date: $WCDATE$