1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-22 18:02:25 +01:00
php-dibi/examples/substitutions.php

40 lines
729 B
PHP
Raw Normal View History

2008-07-17 03:51:29 +00:00
<h1>dibi prefix & substitute example</h1>
<?php
require_once 'Nette/Debug.php';
2008-07-17 03:51:29 +00:00
require_once '../dibi/dibi.php';
dibi::connect(array(
'driver' => 'sqlite',
'database' => 'data/sample.sdb',
2008-07-17 03:51:29 +00:00
));
2008-10-28 02:06:55 +00:00
2008-07-17 03:51:29 +00:00
// create new substitution :blog: ==> wp_
dibi::addSubst('blog', 'wp_');
dibi::test("UPDATE :blog:items SET [text]='Hello World'");
// -> UPDATE wp_items SET [text]='Hello World'
2008-10-28 02:06:55 +00:00
2008-07-17 03:51:29 +00:00
2008-10-28 02:06:55 +00:00
// create substitution fallback
2008-07-17 03:51:29 +00:00
function substFallBack($expr)
{
if (defined($expr)) {
return constant($expr);
} else {
return 'the_' . $expr;
}
2008-07-17 03:51:29 +00:00
}
dibi::setSubstFallBack('substFallBack');
dibi::test("UPDATE [:account:user] SET [name]='John Doe', [active]=:true:");
// -> UPDATE [the_accountuser] SET [name]='John Doe', [active]=1