From f766827219368288cc92a80581184a22949d7da4 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 11 May 2007 22:25:32 +0000 Subject: [PATCH] bugfix, enhanced error reporting, better examples --- dibi/dibi.php | 9 ++- dibi/drivers/mysql.php | 4 +- dibi/drivers/mysqli.php | 2 +- dibi/drivers/odbc.php | 10 +-- dibi/drivers/pdo.php | 2 +- dibi/drivers/postgre.php | 4 +- dibi/drivers/sqlite.php | 4 +- dibi/libs/driver.php | 4 +- examples/connect.php | 13 ++-- examples/dump.php | 15 ++-- examples/fetch.php | 56 ++++++++++---- examples/log.sql | 154 +++++-------------------------------- examples/logger.php | 17 ++-- examples/metatypes.php | 14 ++-- examples/sample.sdb | Bin 0 -> 5120 bytes examples/sql-builder.php | 9 +-- examples/sql-condition.php | 25 +++--- examples/table-prefix.php | 9 +-- version.txt | 2 +- 19 files changed, 123 insertions(+), 230 deletions(-) create mode 100644 examples/sample.sdb diff --git a/dibi/dibi.php b/dibi/dibi.php index d8ac90a8..05f9197f 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -12,7 +12,7 @@ * @license GNU GENERAL PUBLIC LICENSE version 2 * @package dibi * @category Database - * @version 0.8 (Revision: $WCREV$, Date: $WCDATE$) + * @version 0.8b (Revision: $WCREV$, Date: $WCDATE$) */ @@ -26,7 +26,7 @@ */ -define('DIBI', '0.8 (Revision: $WCREV$, Date: $WCDATE$)'); +define('DIBI', '0.8b (Revision: $WCREV$, Date: $WCDATE$)'); if (version_compare(PHP_VERSION , '5.0.3', '<')) @@ -240,7 +240,10 @@ class dibi */ static public function query($args) { - $args = func_get_args(); + // receive arguments + if (!is_array($args)) + $args = func_get_args(); + return self::getConnection()->query($args); } diff --git a/dibi/drivers/mysql.php b/dibi/drivers/mysql.php index ce3c87be..e2c06947 100644 --- a/dibi/drivers/mysql.php +++ b/dibi/drivers/mysql.php @@ -80,7 +80,7 @@ class DibiMySqlDriver extends DibiDriver if (!is_resource($conn)) - throw new DibiException("Connecting error", array( + throw new DibiException("Connecting error (driver mysql)'", array( 'message' => mysql_error() ? mysql_error() : $php_errormsg, 'code' => mysql_errno(), )); @@ -94,7 +94,7 @@ class DibiMySqlDriver extends DibiDriver if (!empty($config['database'])) { if (!@mysql_select_db($config['database'], $conn)) - throw new DibiException("Connecting error", array( + throw new DibiException("Connecting error (driver mysql)", array( 'message' => mysql_error($conn), 'code' => mysql_errno($conn), )); diff --git a/dibi/drivers/mysqli.php b/dibi/drivers/mysqli.php index 75faa92c..db9cb118 100644 --- a/dibi/drivers/mysqli.php +++ b/dibi/drivers/mysqli.php @@ -65,7 +65,7 @@ class DibiMySqliDriver extends DibiDriver $conn = @mysqli_connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']); if (!$conn) - throw new DibiException("Connecting error", array( + throw new DibiException("Connecting error (driver mysqli)", array( 'message' => mysqli_connect_error(), 'code' => mysqli_connect_errno(), )); diff --git a/dibi/drivers/odbc.php b/dibi/drivers/odbc.php index 69e521f5..cc301c8a 100644 --- a/dibi/drivers/odbc.php +++ b/dibi/drivers/odbc.php @@ -48,13 +48,13 @@ class DibiOdbcDriver extends DibiDriver if (empty($config['database'])) $config['database'] = ini_get('odbc.default_db'); if (empty($config['username'])) - throw new DibiException("Username must be specified"); + throw new DibiException("Username must be specified (driver odbc)"); if (empty($config['password'])) - throw new DibiException("Password must be specified"); + throw new DibiException("Password must be specified (driver odbc)"); if (empty($config['database'])) - throw new DibiException("Database must be specified"); + throw new DibiException("Database must be specified (driver odbc)"); parent::__construct($config); } @@ -71,7 +71,7 @@ class DibiOdbcDriver extends DibiDriver $conn = @odbc_pconnect($config['database'], $config['username'], $config['password']); if (!is_resource($conn)) - throw new DibiException("Connecting error", array( + throw new DibiException("Connecting error (driver odbc)", array( 'message' => odbc_errormsg(), 'code' => odbc_error(), )); @@ -177,7 +177,7 @@ class DibiOdbcDriver extends DibiDriver if ($limit >= 0) $sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ')'; - if ($offset) throw new DibiException('Offset is not implemented.'); + if ($offset) throw new DibiException('Offset is not implemented in driver odbc'); } diff --git a/dibi/drivers/pdo.php b/dibi/drivers/pdo.php index b3e50654..c2100fd0 100644 --- a/dibi/drivers/pdo.php +++ b/dibi/drivers/pdo.php @@ -42,7 +42,7 @@ class DibiPdoDriver extends DibiDriver throw new DibiException("PHP extension 'pdo' is not loaded"); if (empty($config['dsn'])) - throw new DibiException("DSN must be specified"); + throw new DibiException("DSN must be specified (driver odbc)"); if (empty($config['username'])) $config['username'] = NULL; if (empty($config['password'])) $config['password'] = NULL; diff --git a/dibi/drivers/postgre.php b/dibi/drivers/postgre.php index b07ace60..e3e3663f 100644 --- a/dibi/drivers/postgre.php +++ b/dibi/drivers/postgre.php @@ -43,7 +43,7 @@ class DibiPostgreDriver extends DibiDriver throw new DibiException("PHP extension 'pgsql' is not loaded"); if (empty($config['string'])) - throw new DibiException("Connection string must be specified"); + throw new DibiException("Connection string must be specified (driver postgre)"); if (empty($config['type'])) $config['type'] = NULL; @@ -62,7 +62,7 @@ class DibiPostgreDriver extends DibiDriver $conn = @pg_pconnect($config['string'], $config['type']); if (!is_resource($conn)) - throw new DibiException("Connecting error", array( + throw new DibiException("Connecting error (driver postgre)", array( 'message' => pg_last_error(), )); diff --git a/dibi/drivers/sqlite.php b/dibi/drivers/sqlite.php index 37fd0f8d..206c33fe 100644 --- a/dibi/drivers/sqlite.php +++ b/dibi/drivers/sqlite.php @@ -44,7 +44,7 @@ class DibiSqliteDriver extends DibiDriver throw new DibiException("PHP extension 'sqlite' is not loaded"); if (empty($config['database'])) - throw new DibiException("Database must be specified"); + throw new DibiException("Database must be specified (driver sqlite)"); if (!isset($config['mode'])) $config['mode'] = 0666; @@ -65,7 +65,7 @@ class DibiSqliteDriver extends DibiDriver $conn = @sqlite_popen($config['database'], $config['mode'], $errorMsg); if (!$conn) - throw new DibiException("Connecting error", array( + throw new DibiException("Connecting error (driver sqlite)", array( 'message' => $errorMsg, )); diff --git a/dibi/libs/driver.php b/dibi/libs/driver.php index be320c50..873ae4d5 100644 --- a/dibi/libs/driver.php +++ b/dibi/libs/driver.php @@ -123,13 +123,14 @@ abstract class DibiDriver dibi::log( "ERROR: $info[message]" . "\n-- SQL: " . $sql + . "\n-- driver: " . $this->config['driver'] . ";\n-- " . date('Y-m-d H:i:s ') ); } if (dibi::$throwExceptions) { $info = $this->errorInfo(); - throw new DibiException('Query error', $info, $sql); + throw new DibiException('Query error (driver ' . $this->config['driver'] . ')', $info, $sql); } else { $info = $this->errorInfo(); if ($info['code']) $info['message'] = "[$info[code]] $info[message]"; @@ -146,6 +147,7 @@ abstract class DibiDriver "OK: " . $sql . ";\n-- result: $msg" . "\n-- takes: " . sprintf('%0.3f', $timer * 1000) . ' ms' + . "\n-- driver: " . $this->config['driver'] . "\n-- " . date('Y-m-d H:i:s ') ); } diff --git a/examples/connect.php b/examples/connect.php index afa92ea7..23b4b303 100644 --- a/examples/connect.php +++ b/examples/connect.php @@ -5,6 +5,12 @@ require_once '../dibi/dibi.php'; try { + // connects to SQlite + dibi::connect(array( + 'driver' => 'sqlite', + 'database' => 'sample.sdb', + )); + // connects to MySQL using DSN dibi::connect('driver=mysql&host=localhost&username=root&password=xxx&database=test&charset=utf8'); @@ -29,13 +35,6 @@ try { )); - // connects to SQlite - dibi::connect(array( - 'driver' => 'sqlite', - 'database' => 'mydb.sdb', - )); - - // connects to PostgreSql dibi::connect(array( 'driver' => 'postgre', diff --git a/examples/dump.php b/examples/dump.php index 354a1409..791387e7 100644 --- a/examples/dump.php +++ b/examples/dump.php @@ -6,19 +6,18 @@ if (function_exists('date_default_timezone_set')) date_default_timezone_set('Europe/Prague'); -// CHANGE TO REAL PARAMETERS! dibi::connect(array( - 'driver' => 'mysql', - 'host' => 'localhost', - 'username' => 'root', - 'password' => 'xxx', - 'database' => 'dibi', - 'charset' => 'utf8', + 'driver' => 'sqlite', + 'database' => 'sample.sdb', )); -$res = dibi::query('SELECT * FROM [mytable]'); +$res = dibi::query(' +SELECT * FROM [products] +INNER JOIN [orders] USING ([product_id]) +INNER JOIN [customers] USING ([customer_id]) +'); // get last SQL $sql = dibi::$sql; diff --git a/examples/fetch.php b/examples/fetch.php index ce76c86b..86bceb9b 100644 --- a/examples/fetch.php +++ b/examples/fetch.php @@ -4,42 +4,72 @@ require_once '../dibi/dibi.php'; -// CHANGE TO REAL PARAMETERS! dibi::connect(array( - 'driver' => 'mysql', - 'host' => 'localhost', - 'username' => 'root', - 'password' => 'xxx', - 'database' => 'dibi', - 'charset' => 'utf8', + 'driver' => 'sqlite', + 'database' => 'sample.sdb', )); -$res = dibi::query('SELECT * FROM [mytable]'); -if (!$res) die('SQL error'); +/* +TABLE products + +product_id | title +-----------+---------- + 1 | Chair + 2 | Table + 3 | Computer + +*/ // fetch a single value +$res = dibi::query('SELECT [title] FROM [products]'); +if (!$res) die('SQL error'); + $value = $res->fetchSingle(); +print_r($value); // Chair +echo '
'; + // fetch complete result set +$res = dibi::query('SELECT * FROM [products]'); $all = $res->fetchAll(); +print_r($all); +echo '
'; + // fetch complete result set like association array -$assoc = $res->fetchAssoc('id'); +$assoc = $res->fetchAssoc('title'); // key +print_r($assoc); +echo '
'; -$assoc = $res->fetchAssoc('id', 'id2'); // fetch complete result set like pairs key => value -$pairs = $res->fetchPairs('id', 'name'); +$pairs = $res->fetchPairs('product_id', 'title'); +print_r($pairs); +echo '
'; // fetch row by row foreach ($res as $row => $fields) { print_r($fields); } +echo '
'; + // fetch row by row with defined offset and limit -foreach ($res->getIterator(2, 3) as $row => $fields) { +foreach ($res->getIterator(2, 1) as $row => $fields) { print_r($fields); } + + +// more complex association array +$res = dibi::query(' +SELECT * FROM [products] +INNER JOIN [orders] USING ([product_id]) +INNER JOIN [customers] USING ([customer_id]) +'); + +$assoc = $res->fetchAssoc('customers.name,products.title'); // key +print_r($assoc); +echo '
'; diff --git a/examples/log.sql b/examples/log.sql index 3a3823f9..aa7615f8 100644 --- a/examples/log.sql +++ b/examples/log.sql @@ -1,140 +1,24 @@ -OK: connected to DB 'mysql' +OK: connected to DB 'sqlite' -OK: SELECT * FROM `mytable` WHERE `inumber` = 38; --- result: object(DibiMySqlResult) rows: 0 --- takes: 1.109 ms --- 2007-02-02 04:38:34 +OK: SELECT * FROM [customers] WHERE [customer_id] = 1; +-- result: object(DibiSqliteResult) rows: 1 +-- takes: 0.331 ms +-- driver: sqlite +-- 2007-05-12 00:14:11 -OK: SELECT * FROM `mytable` WHERE `inumber` < 38; --- result: object(DibiMySqlResult) rows: 12 --- takes: 1.492 ms --- 2007-02-02 04:38:34 +OK: SELECT * FROM [customers] WHERE [customer_id] < 5; +-- result: object(DibiSqliteResult) rows: 4 +-- takes: 0.324 ms +-- driver: sqlite +-- 2007-05-12 00:14:11 -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-02-02 04:38:34 +ERROR: [1] SQL logic error or missing database +-- SQL: SELECT FROM [customers] WHERE [customer_id] < 5 +-- driver: sqlite; +-- 2007-05-12 00:14:11 -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-02-02 04:38:34 - -OK: connected to DB 'mysql' - -OK: SELECT * FROM `mytable` WHERE `inumber` = 38; --- result: object(DibiMySqlResult) rows: 0 --- takes: 1.565 ms --- 2007-02-02 04:47:37 - -OK: SELECT * FROM `mytable` WHERE `inumber` < 38; --- result: object(DibiMySqlResult) rows: 12 --- takes: 1.347 ms --- 2007-02-02 04:47:37 - -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-02-02 04:47:37 - -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-02-02 04:47:37 - -OK: connected to DB 'mysql' - -OK: SELECT * FROM `mytable` WHERE `inumber` = 38; --- result: object(DibiMySqlResult) rows: 0 --- takes: 1.147 ms --- 2007-02-02 04:47:56 - -OK: SELECT * FROM `mytable` WHERE `inumber` < 38; --- result: object(DibiMySqlResult) rows: 12 --- takes: 1.085 ms --- 2007-02-02 04:47:56 - -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-02-02 04:47:56 - -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-02-02 04:47:57 - -OK: connected to DB 'mysql' - -OK: SELECT * FROM `mytable` WHERE `inumber` = 38; --- result: object(DibiMySqlResult) rows: 0 --- takes: 0.944 ms --- 2007-02-02 04:48:23 - -OK: SELECT * FROM `mytable` WHERE `inumber` < 38; --- result: object(DibiMySqlResult) rows: 12 --- takes: 1.258 ms --- 2007-02-02 04:48:23 - -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-02-02 04:48:23 - -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-02-02 04:48:23 - -OK: connected to DB 'mysql' - -OK: SELECT * FROM `mytable` WHERE `inumber` = 38; --- result: object(DibiMySqlResult) rows: 0 --- takes: 1.039 ms --- 2007-02-02 04:50:46 - -OK: SELECT * FROM `mytable` WHERE `inumber` < 38; --- result: object(DibiMySqlResult) rows: 12 --- takes: 1.499 ms --- 2007-02-02 04:50:46 - -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-02-02 04:50:46 - -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-02-02 04:50:46 - -OK: connected to DB 'mysql' - -OK: SELECT * FROM `mytable` WHERE `inumber` = 38; --- result: object(DibiMySqlResult) rows: 0 --- takes: 1.518 ms --- 2007-03-28 00:45:27 - -OK: SELECT * FROM `mytable` WHERE `inumber` < 38; --- result: object(DibiMySqlResult) rows: 12 --- takes: 6.385 ms --- 2007-03-28 00:45:27 - -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-03-28 00:45:27 - -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-03-28 00:45:27 - -OK: connected to DB 'mysql' - -OK: SELECT * FROM `mytable` WHERE `inumber` = 38; --- result: object(DibiMySqlResult) rows: 0 --- takes: 1.124 ms --- 2007-03-28 01:06:07 - -OK: SELECT * FROM `mytable` WHERE `inumber` < 38; --- result: object(DibiMySqlResult) rows: 12 --- takes: 1.607 ms --- 2007-03-28 01:06:07 - -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-03-28 01:06:07 - -ERROR: [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytable` WHERE `inumber` < 38' at line 1 --- SQL: SELECT FROM `mytable` WHERE `inumber` < 38; --- 2007-03-28 01:06:07 +ERROR: [1] SQL logic error or missing database +-- SQL: SELECT FROM [customers] WHERE [customer_id] < 38 +-- driver: sqlite; +-- 2007-05-12 00:14:11 diff --git a/examples/logger.php b/examples/logger.php index 927c9d69..9f99a123 100644 --- a/examples/logger.php +++ b/examples/logger.php @@ -19,14 +19,9 @@ dibi::$logAll = TRUE; -// CHANGE TO REAL PARAMETERS! dibi::connect(array( - 'driver' => 'mysql', - 'host' => 'localhost', - 'username' => 'root', - 'password' => 'xxx', - 'database' => 'dibi', - 'charset' => 'utf8', + 'driver' => 'sqlite', + 'database' => 'sample.sdb', )); @@ -36,13 +31,13 @@ dibi::$throwExceptions = FALSE; echo '

User-level errors

'; -$res = dibi::query('SELECT * FROM [mytable] WHERE [inumber] = %i', 38); +$res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] = %i', 1); -$res = dibi::query('SELECT * FROM [mytable] WHERE [inumber] < %i', 38); +$res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] < %i', 5); -$res = dibi::query('SELECT FROM [mytable] WHERE [inumber] < %i', 38); +$res = dibi::query('SELECT FROM [customers] WHERE [customer_id] < %i', 5); echo "
See file ", dibi::$logFile; @@ -54,7 +49,7 @@ echo '

DibiException

'; try { - $res = dibi::query('SELECT FROM [mytable] WHERE [inumber] < %i', 38); + $res = dibi::query('SELECT FROM [customers] WHERE [customer_id] < %i', 38); } catch (DibiException $e) { diff --git a/examples/metatypes.php b/examples/metatypes.php index 1409daa8..67c964a2 100644 --- a/examples/metatypes.php +++ b/examples/metatypes.php @@ -4,28 +4,24 @@ require_once '../dibi/dibi.php'; -// CHANGE TO REAL PARAMETERS! dibi::connect(array( - 'driver' => 'mysql', - 'host' => 'localhost', - 'username' => 'root', - 'password' => 'xxx', - 'database' => 'dibi', - 'charset' => 'utf8', + 'driver' => 'sqlite', + 'database' => 'sample.sdb', )); -$res = dibi::query('SELECT * FROM [mytable] WHERE [inumber] <> %i', 38); +$res = dibi::query('SELECT * FROM [customers]'); if (!$res) die('SQL error'); // auto-convert this field to integer -$res->setType('inumber', Dibi::FIELD_INTEGER); +$res->setType('customer_id', Dibi::FIELD_INTEGER); $record = $res->fetch(); var_dump($record); // auto-detect all types +// WARNING: THIS WILL NOT WORK WITH SQLITE $res->setType(TRUE); $record = $res->fetch(); var_dump($record); diff --git a/examples/sample.sdb b/examples/sample.sdb new file mode 100644 index 0000000000000000000000000000000000000000..3b25650ea1595561492a247a8465fa8079692e40 GIT binary patch literal 5120 zcmeH}&u-H|5XL956Y|GZRUvXf2u6rQ8X?pq6nfwg;~HAUq+kqERieryi(=u}mF)n% zaX=M)iynB7iW|?sl~>>am|feAr~s7{Aa)O)S$|{em(QBnv|8v)ycl12KEqKMB(4|4 z=mz-sk>w=}J2%=mb`$rx8#8RRpgH^U8M1Yy1fb>{8Knc#fq&A03TQBK7+j|9M48cJWsk{*rx87=;(JX6L<28AvPCk`EJ)64{>wgnD=Go0tWG70BmT%9-7P!-&qV4uF&p6>RXH&}B`HPp1Q?@V~bFeI| zo}x-`r${0{8_%!lxtrOC`0?v_fjbRnK{CX9)|T$fzX~@SzLLvw{eKQr;FVF9nj;3oiN;Gb(F2O28R2wqmaqsuDEz)$(gEqf-|RpIJ_$S( zniLna{$E^oUoo`2n74AKTNIbLPBUOhkAl!2qwP)U3{ETfSv{e&p3Q=~Ght}BNvf*w zjuJ6nRGJ|hq3`d{=gSdkHU3;lQEL5YKViXl^QFPHvZ6Hl5ixlI!+toLxIz5VgZ1K? zoHgX1T+)Hxcc21q#6#)%FM797DxIs=JJ5#P>HAdZQ6jWrrgfo{YyAI1+VetdlhVyK Z9)+d~?G`Dk0PkhLrUuEYbl?v<@C~KM&!7MR literal 0 HcmV?d00001 diff --git a/examples/sql-builder.php b/examples/sql-builder.php index 68745a65..f3ed48aa 100644 --- a/examples/sql-builder.php +++ b/examples/sql-builder.php @@ -11,14 +11,9 @@ if (function_exists('date_default_timezone_set')) date_default_timezone_set('Europe/Prague'); // or 'GMT' -// CHANGE TO REAL PARAMETERS! dibi::connect(array( - 'driver' => 'mysql', - 'host' => 'localhost', - 'username' => 'root', - 'password' => 'xxx', - 'database' => 'dibi', - 'charset' => 'utf8', + 'driver' => 'sqlite', + 'database' => 'sample.sdb', )); diff --git a/examples/sql-condition.php b/examples/sql-condition.php index 252e991e..92cc7d7a 100644 --- a/examples/sql-condition.php +++ b/examples/sql-condition.php @@ -7,14 +7,9 @@ pre.dibi { padding-bottom: 10px; } require_once '../dibi/dibi.php'; -// CHANGE TO REAL PARAMETERS! dibi::connect(array( - 'driver' => 'mysql', - 'host' => 'localhost', - 'username' => 'root', - 'password' => 'xxx', - 'database' => 'dibi', - 'charset' => 'utf8', + 'driver' => 'sqlite', + 'database' => 'sample.sdb', )); @@ -22,29 +17,29 @@ $cond1 = rand(0,2) < 1; $cond2 = rand(0,2) < 1; -$user = $cond1 ? 'Davidek' : NULL; - +$name = $cond1 ? 'K%' : NULL; +// if & end dibi::test(' SELECT * -FROM [mytable] -%if', isset($user), 'WHERE [user]=%s', $user, '%end' +FROM [customers] +%if', isset($name), 'WHERE [name] LIKE %s', $name, '%end' ); -// last end is optional +// if & else & end (last end is optional) dibi::test(' SELECT * -FROM %if', $cond1, '[one_table] %else [second_table]' +FROM %if', $cond1, '[customers] %else [products]' ); // nested condition dibi::test(' SELECT * -FROM [mytable] +FROM [customers] WHERE - %if', isset($user), '[user]=%s', $user, ' + %if', isset($name), '[name] LIKE %s', $name, ' %if', $cond2, 'AND [admin]=1 %end %else LIMIT 10 %end' ); diff --git a/examples/table-prefix.php b/examples/table-prefix.php index 4c937d47..e9bc57fc 100644 --- a/examples/table-prefix.php +++ b/examples/table-prefix.php @@ -3,14 +3,9 @@ require_once '../dibi/dibi.php'; -// CHANGE TO REAL PARAMETERS! dibi::connect(array( - 'driver' => 'mysql', - 'host' => 'localhost', - 'username' => 'root', - 'password' => 'xxx', - 'database' => 'dibi', - 'charset' => 'utf8', + 'driver' => 'sqlite', + 'database' => 'sample.sdb', )); diff --git a/version.txt b/version.txt index 19ed6bfc..b127ab75 100644 --- a/version.txt +++ b/version.txt @@ -1,4 +1,4 @@ -Dibi version 0.8 +Dibi version 0.8b Revision: $WCREV$ Date: $WCDATE$