2006-06-07 19:02:24 +00:00
|
|
|
<style>
|
|
|
|
pre.dibi { padding-bottom: 10px; }
|
|
|
|
</style>
|
|
|
|
<pre>
|
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once '../dibi/dibi.php';
|
|
|
|
|
|
|
|
|
2007-02-02 03:51:43 +00:00
|
|
|
// CHANGE TO REAL PARAMETERS!
|
2006-06-07 19:02:24 +00:00
|
|
|
dibi::connect(array(
|
2006-09-23 06:34:44 +00:00
|
|
|
'driver' => 'mysql',
|
2006-06-07 19:02:24 +00:00
|
|
|
'host' => 'localhost',
|
|
|
|
'username' => 'root',
|
2007-02-02 03:51:43 +00:00
|
|
|
'password' => 'xxx',
|
|
|
|
'database' => 'dibi',
|
2006-06-07 19:02:24 +00:00
|
|
|
'charset' => 'utf8',
|
|
|
|
));
|
|
|
|
|
|
|
|
|
2006-06-08 02:02:05 +00:00
|
|
|
$cond1 = rand(0,2) < 1;
|
|
|
|
$cond2 = rand(0,2) < 1;
|
2006-06-07 19:02:24 +00:00
|
|
|
|
|
|
|
|
2006-06-07 21:33:46 +00:00
|
|
|
$user = $cond1 ? 'Davidek' : NULL;
|
2006-06-07 19:02:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
dibi::test('
|
|
|
|
SELECT *
|
2007-02-02 03:51:43 +00:00
|
|
|
FROM [mytable]
|
2006-06-07 21:33:46 +00:00
|
|
|
%if', isset($user), 'WHERE [user]=%s', $user, '%end'
|
2006-06-07 19:02:24 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2006-06-07 21:33:46 +00:00
|
|
|
// last end is optional
|
2006-06-07 19:02:24 +00:00
|
|
|
dibi::test('
|
|
|
|
SELECT *
|
2006-06-07 21:33:46 +00:00
|
|
|
FROM %if', $cond1, '[one_table] %else [second_table]'
|
2006-06-07 19:02:24 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// nested condition
|
|
|
|
dibi::test('
|
|
|
|
SELECT *
|
2007-02-02 03:51:43 +00:00
|
|
|
FROM [mytable]
|
2006-06-08 02:02:05 +00:00
|
|
|
WHERE
|
2006-06-07 21:33:46 +00:00
|
|
|
%if', isset($user), '[user]=%s', $user, '
|
|
|
|
%if', $cond2, 'AND [admin]=1 %end
|
|
|
|
%else LIMIT 10 %end'
|
2006-06-07 19:02:24 +00:00
|
|
|
);
|