mirror of
https://github.com/dg/dibi.git
synced 2025-07-10 09:06:24 +02:00
update to 0.6
This commit is contained in:
@ -1,3 +1,6 @@
|
||||
<style>
|
||||
pre.dibi { padding-bottom: 10px; }
|
||||
</style>
|
||||
<pre>
|
||||
<?php
|
||||
|
||||
@ -9,35 +12,37 @@ dibi::connect(array(
|
||||
'driver' => 'mysqli',
|
||||
'host' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => '***',
|
||||
'database' => 'test',
|
||||
'password' => 'xxx', // change to real password!
|
||||
'charset' => 'utf8',
|
||||
));
|
||||
|
||||
|
||||
|
||||
$arr1 = array(1, 2, 3);
|
||||
$arr2 = array('one', 'two', 'three');
|
||||
$arr3 = array(
|
||||
'a' => 'one',
|
||||
'b' => 'two',
|
||||
'c' => 'three',
|
||||
'col1' => 'one',
|
||||
'col2' => 'two',
|
||||
'col3' => 'three',
|
||||
);
|
||||
$arr4 = array(
|
||||
'A' => 12,
|
||||
'B' => NULL,
|
||||
'C' => new TDateTime(31542),
|
||||
'D' => 'string',
|
||||
'a' => 12,
|
||||
'b' => NULL,
|
||||
'c%T' => time(), // modifier 'T' means datetime
|
||||
'd' => 'any string',
|
||||
);
|
||||
$arr5 = array('RAND()', 'ANY SQL');
|
||||
|
||||
dibi::test(
|
||||
"
|
||||
|
||||
dibi::test("
|
||||
SELECT *
|
||||
FROM [test]
|
||||
WHERE ([test.a] LIKE %T", '1995-03-01', "
|
||||
OR [b1] IN (", $arr1, ")
|
||||
OR [b2] IN (", $arr2, ")
|
||||
OR [b3] IN (%N", $arr3, ")
|
||||
OR [b4] IN %V", $arr4, "
|
||||
FROM [db.table]
|
||||
WHERE ([test.a] LIKE %D", '1995-03-01', "
|
||||
OR [b1] IN (", $arr1, ")
|
||||
OR [b2] IN (%s", $arr1, ")
|
||||
OR [b3] IN (", $arr2, ")
|
||||
OR [b4] IN (%n", $arr3, ")
|
||||
OR [b4] IN (%p", $arr5, ")
|
||||
AND [c] = 'embedded '' string'
|
||||
OR [d]=%d", 10.3, "
|
||||
OR [true]=", true, "
|
||||
@ -45,4 +50,17 @@ WHERE ([test.a] LIKE %T", '1995-03-01', "
|
||||
OR [null]=", NULL, "
|
||||
LIMIT 10");
|
||||
|
||||
|
||||
// dibi detects INSERT or REPLACE command
|
||||
dibi::test("INSERT INTO [test]", $arr4);
|
||||
|
||||
|
||||
// dibi detects UPDATE command
|
||||
$n = 123;
|
||||
dibi::test("UPDATE [test] SET", $arr4, " WHERE [id]=%n", $n);
|
||||
|
||||
|
||||
// array with modifier %d - means strings
|
||||
dibi::test("UPDATE [test] SET%s", $arr4, " WHERE [id]=%n", $n);
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user