mirror of
https://github.com/dg/dibi.git
synced 2025-08-01 11:50:15 +02:00
+ rewritten support for logging & error handling
+ modifier %sn * modifier %sql * changed modifier behaviour: NULL is always 'NULL'
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
|
||||
require_once '../dibi/dibi.php';
|
||||
|
||||
dibi::$debug = true;
|
||||
|
||||
// mysql
|
||||
dibi::connect(array(
|
||||
|
@@ -4,9 +4,20 @@
|
||||
require_once '../dibi/dibi.php';
|
||||
|
||||
|
||||
// required since PHP 5.1.0
|
||||
if (function_exists('date_default_timezone_set'))
|
||||
date_default_timezone_set('Europe/Prague'); // or 'GMT'
|
||||
|
||||
|
||||
// enable log to this file
|
||||
dibi::$logFile = 'log.sql';
|
||||
|
||||
// append mode
|
||||
dibi::$logMode = 'a';
|
||||
|
||||
// log all queries
|
||||
dibi::$logAll = TRUE;
|
||||
|
||||
|
||||
// mysql
|
||||
dibi::connect(array(
|
||||
@@ -14,7 +25,7 @@ dibi::connect(array(
|
||||
'host' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'xxx', // change to real password!
|
||||
'database' => 'test',
|
||||
'database' => 'xxx',
|
||||
'charset' => 'utf8',
|
||||
));
|
||||
|
||||
|
@@ -6,7 +6,6 @@ pre.dibi { padding-bottom: 10px; }
|
||||
|
||||
require_once '../dibi/dibi.php';
|
||||
|
||||
|
||||
// required since PHP 5.1.0
|
||||
if (function_exists('date_default_timezone_set'))
|
||||
date_default_timezone_set('Europe/Prague'); // or 'GMT'
|
||||
@@ -33,9 +32,8 @@ $arr3 = array(
|
||||
$arr4 = array(
|
||||
'a' => 12,
|
||||
'b' => NULL,
|
||||
'c%?' => NULL,
|
||||
'd%t' => time(), // modifier 'T' means datetime
|
||||
'e' => 'any string',
|
||||
'c%t' => time(), // modifier 'T' means datetime
|
||||
'd' => 'any string',
|
||||
);
|
||||
$arr5 = array('RAND()', '[col1] > [col2]');
|
||||
|
||||
@@ -48,12 +46,15 @@ WHERE ([test.a] LIKE %d", '1995-03-01', "
|
||||
OR [b2] IN (%s", $arr1, ")
|
||||
OR [b3] IN (", $arr2, ")
|
||||
OR [b4] IN (%n", $arr3, ")
|
||||
OR [b4] IN (%p", $arr5, ")
|
||||
OR [b5] IN (%sql", $arr5, ")
|
||||
OR [b6] IN (", array(), ")
|
||||
AND [c] = 'embedded '' string'
|
||||
OR [d]=%i", 10.3, "
|
||||
OR [true]=", true, "
|
||||
OR [false]=", false, "
|
||||
OR [null]=", NULL, "
|
||||
OR [e]=%i", NULL, "
|
||||
OR [true]=", TRUE, "
|
||||
OR [false]=", FALSE, "
|
||||
OR [str_null]=%sn", '', "
|
||||
OR [str_not_null]=%sn", 'hello', "
|
||||
LIMIT 10");
|
||||
|
||||
|
||||
@@ -66,7 +67,8 @@ $n = 123;
|
||||
dibi::test("UPDATE [test] SET", $arr4, " WHERE [id]=%i", $n);
|
||||
|
||||
|
||||
// array with modifier %a - means strings
|
||||
// array with modifier %a - assoc
|
||||
dibi::test("UPDATE [test] SET%a", $arr4, " WHERE [id]=%i", $n);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
@@ -13,7 +13,7 @@ dibi::connect(array(
|
||||
));
|
||||
|
||||
|
||||
// create new substitution :blog: ==> wp_items_
|
||||
// create new substitution :blog: ==> wp_
|
||||
dibi::addSubst('blog', 'wp_');
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user