mirror of
https://github.com/dg/dibi.git
synced 2025-08-29 08:49:50 +02:00
- improved examples
This commit is contained in:
@@ -19,11 +19,13 @@ dibi::connect(array(
|
||||
|
||||
// dibi detects INSERT or REPLACE command
|
||||
dibi::test('
|
||||
REPLACE INTO [products]', array(
|
||||
'title' => 'Drti<EFBFBD>ka na tr<74>vu',
|
||||
'price' => 318,
|
||||
'active' => TRUE,
|
||||
REPLACE INTO [products]', array(
|
||||
'title' => 'Super product',
|
||||
'price' => 318,
|
||||
'active' => TRUE,
|
||||
));
|
||||
// -> REPLACE INTO [products] ([title], [price], [active]) VALUES ('Super product', 318, 1)
|
||||
|
||||
|
||||
|
||||
// multiple INSERT command
|
||||
@@ -34,15 +36,19 @@ $array = array(
|
||||
'created' => dibi::datetime(),
|
||||
);
|
||||
dibi::test("INSERT INTO [products]", $array, $array, $array);
|
||||
// -> INSERT INTO [products] ([title], [price], [brand], [created]) VALUES ('Super Product', ...) , (...) , (...)
|
||||
|
||||
|
||||
|
||||
// dibi detects UPDATE command
|
||||
dibi::test("
|
||||
UPDATE [colors] SET", array(
|
||||
'color' => 'blue',
|
||||
'order' => 12,
|
||||
), "
|
||||
WHERE [id]=%i", 123);
|
||||
UPDATE [colors] SET", array(
|
||||
'color' => 'blue',
|
||||
'order' => 12,
|
||||
), "
|
||||
WHERE [id]=%i", 123);
|
||||
// -> UPDATE [colors] SET [color]='blue', [order]=12 WHERE [id]=123
|
||||
|
||||
|
||||
|
||||
// SELECT
|
||||
@@ -50,20 +56,24 @@ $ipMask = '192.168.%';
|
||||
$timestamp = mktime(0, 0, 0, 10, 13, 1997);
|
||||
|
||||
dibi::test('
|
||||
SELECT COUNT(*) as [count]
|
||||
FROM [comments]
|
||||
WHERE [ip] LIKE %s', $ipMask, '
|
||||
AND [date] > ', dibi::date($timestamp)
|
||||
SELECT COUNT(*) as [count]
|
||||
FROM [comments]
|
||||
WHERE [ip] LIKE %s', $ipMask, '
|
||||
AND [date] > ', dibi::date($timestamp)
|
||||
);
|
||||
// -> SELECT COUNT(*) as [count] FROM [comments] WHERE [ip] LIKE '192.168.%' AND [date] > 876693600
|
||||
|
||||
|
||||
|
||||
// IN array
|
||||
$array = array(1, 2, 3);
|
||||
dibi::test("
|
||||
SELECT *
|
||||
FROM [people]
|
||||
WHERE [id] IN (", $array, ")
|
||||
SELECT *
|
||||
FROM [people]
|
||||
WHERE [id] IN (", $array, ")
|
||||
");
|
||||
// -> SELECT * FROM [people] WHERE [id] IN ( 1, 2, 3 )
|
||||
|
||||
|
||||
|
||||
// ORDER BY array
|
||||
@@ -76,3 +86,4 @@ SELECT *
|
||||
FROM [people]
|
||||
ORDER BY %by", $order, "
|
||||
");
|
||||
// -> SELECT * FROM [people] ORDER BY [field1] ASC, [field2] DESC
|
||||
|
Reference in New Issue
Block a user