\n";
diff --git a/examples/dumping-sql-and-result-set.php b/examples/dumping-sql-and-result-set.php
index d23015a6..d2ed27d3 100644
--- a/examples/dumping-sql-and-result-set.php
+++ b/examples/dumping-sql-and-result-set.php
@@ -9,13 +9,13 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
}
-dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
]);
-$res = dibi::query('
+$res = $dibi->query('
SELECT * FROM products
INNER JOIN orders USING (product_id)
INNER JOIN customers USING (customer_id)
diff --git a/examples/fetching-examples.php b/examples/fetching-examples.php
index 3bf0b694..cf879abb 100644
--- a/examples/fetching-examples.php
+++ b/examples/fetching-examples.php
@@ -13,7 +13,7 @@ Tracy\Debugger::enable();
'sqlite3',
'database' => 'data/sample.s3db',
]);
@@ -33,46 +33,46 @@ product_id | title
// fetch a single row
echo "
fetch()
\n";
-$row = dibi::fetch('SELECT title FROM products');
+$row = $dibi->fetch('SELECT title FROM products');
Tracy\Dumper::dump($row); // Chair
// fetch a single value
echo "
fetchSingle()
\n";
-$value = dibi::fetchSingle('SELECT title FROM products');
+$value = $dibi->fetchSingle('SELECT title FROM products');
Tracy\Dumper::dump($value); // Chair
// fetch complete result set
echo "
fetchAll()
\n";
-$all = dibi::fetchAll('SELECT * FROM products');
+$all = $dibi->fetchAll('SELECT * FROM products');
Tracy\Dumper::dump($all);
// fetch complete result set like association array
echo "
fetchAssoc('title')
\n";
-$res = dibi::query('SELECT * FROM products');
+$res = $dibi->query('SELECT * FROM products');
$assoc = $res->fetchAssoc('title'); // key
Tracy\Dumper::dump($assoc);
// fetch complete result set like pairs key => value
echo "
fetchPairs('product_id', 'title')
\n";
-$res = dibi::query('SELECT * FROM products');
+$res = $dibi->query('SELECT * FROM products');
$pairs = $res->fetchPairs('product_id', 'title');
Tracy\Dumper::dump($pairs);
// fetch row by row
echo "
using foreach
\n";
-$res = dibi::query('SELECT * FROM products');
+$res = $dibi->query('SELECT * FROM products');
foreach ($res as $n => $row) {
Tracy\Dumper::dump($row);
}
// more complex association array
-$res = dibi::query('
+$res = $dibi->query('
SELECT *
FROM products
INNER JOIN orders USING (product_id)
@@ -84,11 +84,11 @@ $assoc = $res->fetchAssoc('name|title'); // key
Tracy\Dumper::dump($assoc);
echo "
fetchAssoc('name[]title')
\n";
-$res = dibi::query('SELECT * FROM products INNER JOIN orders USING (product_id) INNER JOIN customers USING (customer_id)');
+$res = $dibi->query('SELECT * FROM products INNER JOIN orders USING (product_id) INNER JOIN customers USING (customer_id)');
$assoc = $res->fetchAssoc('name[]title'); // key
Tracy\Dumper::dump($assoc);
echo "
fetchAssoc('name->title')
\n";
-$res = dibi::query('SELECT * FROM products INNER JOIN orders USING (product_id) INNER JOIN customers USING (customer_id)');
+$res = $dibi->query('SELECT * FROM products INNER JOIN orders USING (product_id) INNER JOIN customers USING (customer_id)');
$assoc = $res->fetchAssoc('name->title'); // key
Tracy\Dumper::dump($assoc);
diff --git a/examples/importing-dump-from-file.php b/examples/importing-dump-from-file.php
index d143c6fc..2bb7005f 100644
--- a/examples/importing-dump-from-file.php
+++ b/examples/importing-dump-from-file.php
@@ -9,12 +9,12 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
}
-dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
]);
-$count = dibi::loadFile('compress.zlib://data/sample.dump.sql.gz');
+$count = $dibi->loadFile('compress.zlib://data/sample.dump.sql.gz');
echo 'Number of SQL commands:', $count;
diff --git a/examples/query-language-and-conditions.php b/examples/query-language-and-conditions.php
index 8996d629..0419e0a2 100644
--- a/examples/query-language-and-conditions.php
+++ b/examples/query-language-and-conditions.php
@@ -9,7 +9,7 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
}
-dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
]);
@@ -25,7 +25,7 @@ $bar = 2;
$name = $cond1 ? 'K%' : null;
// if & end
-dibi::test('
+$dibi->test('
SELECT *
FROM customers
%if', isset($name), 'WHERE name LIKE ?', $name, '%end'
@@ -34,7 +34,7 @@ dibi::test('
// if & else & (optional) end
-dibi::test('
+$dibi->test('
SELECT *
FROM people
WHERE id > 0
@@ -45,7 +45,7 @@ dibi::test('
// nested condition
-dibi::test('
+$dibi->test('
SELECT *
FROM customers
WHERE
@@ -57,7 +57,7 @@ dibi::test('
// IF()
-dibi::test('UPDATE products SET', [
- 'price' => ['IF(price_fixed, price, ?)', 123],
+$dibi->test('UPDATE products SET', [
+ 'price' => $dibi->expression('IF(price_fixed, price, ?)', 123),
]);
// -> SELECT * FROM customers WHERE LIMIT 10
diff --git a/examples/query-language-basic-examples.php b/examples/query-language-basic-examples.php
index 99633959..bbee6c75 100644
--- a/examples/query-language-basic-examples.php
+++ b/examples/query-language-basic-examples.php
@@ -11,7 +11,7 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
date_default_timezone_set('Europe/Prague');
-dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
]);
@@ -21,7 +21,7 @@ dibi::connect([
$ipMask = '192.168.%';
$timestamp = mktime(0, 0, 0, 10, 13, 1997);
-dibi::test('
+$dibi->test('
SELECT COUNT(*) as [count]
FROM [comments]
WHERE [ip] LIKE ?', $ipMask, '
@@ -31,7 +31,7 @@ dibi::test('
// dibi detects INSERT or REPLACE command
-dibi::test('
+$dibi->test('
REPLACE INTO products', [
'title' => 'Super product',
'price' => 318,
@@ -47,12 +47,12 @@ $array = [
'brand' => null,
'created' => new DateTime,
];
-dibi::test('INSERT INTO products', $array, $array, $array);
+$dibi->test('INSERT INTO products', $array, $array, $array);
// -> INSERT INTO products ([title], [price], [brand], [created]) VALUES ('Super Product', ...) , (...) , (...)
// dibi detects UPDATE command
-dibi::test('
+$dibi->test('
UPDATE colors SET', [
'color' => 'blue',
'order' => 12,
@@ -63,7 +63,7 @@ dibi::test('
// modifier applied to array
$array = [1, 2, 3];
-dibi::test('
+$dibi->test('
SELECT *
FROM people
WHERE id IN (?)', $array
@@ -76,7 +76,7 @@ $order = [
'field1' => 'asc',
'field2' => 'desc',
];
-dibi::test('
+$dibi->test('
SELECT *
FROM people
ORDER BY %by', $order, '
@@ -85,5 +85,5 @@ dibi::test('
// indentifiers and strings syntax mix
-dibi::test('UPDATE [table] SET `item` = "5 1/4"" diskette"');
+$dibi->test('UPDATE [table] SET `item` = "5 1/4"" diskette"');
// -> UPDATE [table] SET [item] = '5 1/4" diskette'
diff --git a/examples/result-set-data-types.php b/examples/result-set-data-types.php
index 54ce8b00..f5284b2b 100644
--- a/examples/result-set-data-types.php
+++ b/examples/result-set-data-types.php
@@ -17,14 +17,14 @@ date_default_timezone_set('Europe/Prague');
'sqlite3',
'database' => 'data/sample.s3db',
]);
// using manual hints
-$res = dibi::query('SELECT * FROM [customers]');
+$res = $dibi->query('SELECT * FROM [customers]');
$res->setType('customer_id', Type::INTEGER)
->setType('added', Type::DATETIME)
@@ -40,7 +40,7 @@ Tracy\Dumper::dump($res->fetch());
// using auto-detection (works well with MySQL or other strictly typed databases)
-$res = dibi::query('SELECT * FROM [customers]');
+$res = $dibi->query('SELECT * FROM [customers]');
Tracy\Dumper::dump($res->fetch());
// outputs:
diff --git a/examples/tracy-and-exceptions.php b/examples/tracy-and-exceptions.php
index 385e2648..c29a3e74 100644
--- a/examples/tracy-and-exceptions.php
+++ b/examples/tracy-and-exceptions.php
@@ -9,7 +9,7 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
Tracy\Debugger::enable();
-$connection = dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
'profiler' => [
@@ -20,11 +20,11 @@ $connection = dibi::connect([
// add panel to debug bar
$panel = new Dibi\Bridges\Tracy\Panel;
-$panel->register($connection);
+$panel->register($dibi);
// throws error because SQL is bad
-dibi::query('SELECT FROM customers WHERE customer_id < ?', 38);
+$dibi->query('SELECT FROM customers WHERE customer_id < ?', 38);
?>
diff --git a/examples/tracy.php b/examples/tracy.php
index 16d1ded8..41730a9d 100644
--- a/examples/tracy.php
+++ b/examples/tracy.php
@@ -9,7 +9,7 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
Tracy\Debugger::enable();
-$connection = dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
'profiler' => [
@@ -20,14 +20,14 @@ $connection = dibi::connect([
// add panel to debug bar
$panel = new Dibi\Bridges\Tracy\Panel;
-$panel->register($connection);
+$panel->register($dibi);
// query will be logged
-dibi::query('SELECT 123');
+$dibi->query('SELECT 123');
// result set will be dumped
-Tracy\Debugger::barDump(dibi::fetchAll('SELECT * FROM customers WHERE customer_id < ?', 38), '[customers]');
+Tracy\Debugger::barDump($dibi->fetchAll('SELECT * FROM customers WHERE customer_id < ?', 38), '[customers]');
?>
diff --git a/examples/using-datetime.php b/examples/using-datetime.php
index eeb4e4b2..b222542c 100644
--- a/examples/using-datetime.php
+++ b/examples/using-datetime.php
@@ -12,7 +12,7 @@ date_default_timezone_set('Europe/Prague');
// CHANGE TO REAL PARAMETERS!
-dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
'formatDate' => "'Y-m-d'",
@@ -21,7 +21,7 @@ dibi::connect([
// generate and dump SQL
-dibi::test('
+$dibi->test('
INSERT INTO [mytable]', [
'id' => 123,
'date' => new DateTime('12.3.2007'),
diff --git a/examples/using-extension-methods.php b/examples/using-extension-methods.php
index c424d26f..3e40f276 100644
--- a/examples/using-extension-methods.php
+++ b/examples/using-extension-methods.php
@@ -13,7 +13,7 @@ Tracy\Debugger::enable();
'sqlite3',
'database' => 'data/sample.s3db',
]);
@@ -28,6 +28,6 @@ Dibi\Result::extensionMethod('fetchShuffle', function (Dibi\Result $obj) {
// fetch complete result set shuffled
-$res = dibi::query('SELECT * FROM [customers]');
+$res = $dibi->query('SELECT * FROM [customers]');
$all = $res->fetchShuffle();
Tracy\Dumper::dump($all);
diff --git a/examples/using-fluent-syntax.php b/examples/using-fluent-syntax.php
index 9f3b0140..fbb5d63d 100644
--- a/examples/using-fluent-syntax.php
+++ b/examples/using-fluent-syntax.php
@@ -11,7 +11,7 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
date_default_timezone_set('Europe/Prague');
-dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
]);
@@ -25,7 +25,7 @@ $record = [
];
// SELECT ...
-dibi::select('product_id')->as('id')
+$dibi->select('product_id')->as('id')
->select('title')
->from('products')
->innerJoin('orders')->using('(product_id)')
@@ -37,35 +37,35 @@ dibi::select('product_id')->as('id')
// SELECT ...
-echo dibi::select('title')->as('id')
+echo $dibi->select('title')->as('id')
->from('products')
->fetchSingle();
// -> Chair (as result of query: SELECT [title] AS [id] FROM [products])
// INSERT ...
-dibi::insert('products', $record)
+$dibi->insert('products', $record)
->setFlag('IGNORE')
->test();
// -> INSERT IGNORE INTO [products] ([title], [price], [active]) VALUES ('Super product', 318, 1)
// UPDATE ...
-dibi::update('products', $record)
+$dibi->update('products', $record)
->where('product_id = ?', $id)
->test();
// -> UPDATE [products] SET [title]='Super product', [price]=318, [active]=1 WHERE product_id = 10
// DELETE ...
-dibi::delete('products')
+$dibi->delete('products')
->where('product_id = ?', $id)
->test();
// -> DELETE FROM [products] WHERE product_id = 10
// custom commands
-dibi::command()
+$dibi->command()
->update('products')
->where('product_id = ?', $id)
->set($record)
@@ -73,7 +73,7 @@ dibi::command()
// -> UPDATE [products] SET [title]='Super product', [price]=318, [active]=1 WHERE product_id = 10
-dibi::command()
+$dibi->command()
->truncate('products')
->test();
// -> TRUNCATE [products]
diff --git a/examples/using-limit-and-offset.php b/examples/using-limit-and-offset.php
index 3f096497..dc94a4b6 100644
--- a/examples/using-limit-and-offset.php
+++ b/examples/using-limit-and-offset.php
@@ -9,22 +9,22 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
}
-dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
]);
// no limit
-dibi::test('SELECT * FROM [products]');
+$dibi->test('SELECT * FROM [products]');
// -> SELECT * FROM [products]
// with limit = 2
-dibi::test('SELECT * FROM [products] %lmt', 2);
+$dibi->test('SELECT * FROM [products] %lmt', 2);
// -> SELECT * FROM [products] LIMIT 2
// with limit = 2, offset = 1
-dibi::test('SELECT * FROM [products] %lmt %ofs', 2, 1);
+$dibi->test('SELECT * FROM [products] %lmt %ofs', 2, 1);
// -> SELECT * FROM [products] LIMIT 2 OFFSET 1
diff --git a/examples/using-logger.php b/examples/using-logger.php
index 71b8471f..d95d60a0 100644
--- a/examples/using-logger.php
+++ b/examples/using-logger.php
@@ -11,7 +11,7 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
date_default_timezone_set('Europe/Prague');
-dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
// enable query logging to this file
@@ -23,11 +23,11 @@ dibi::connect([
try {
- $res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] = ?', 1);
+ $res = $dibi->query('SELECT * FROM [customers] WHERE [customer_id] = ?', 1);
- $res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] < ?', 5);
+ $res = $dibi->query('SELECT * FROM [customers] WHERE [customer_id] < ?', 5);
- $res = dibi::query('SELECT FROM [customers] WHERE [customer_id] < ?', 38);
+ $res = $dibi->query('SELECT FROM [customers] WHERE [customer_id] < ?', 38);
} catch (Dibi\Exception $e) {
echo '
', get_class($e), ': ', $e->getMessage(), '
';
}
diff --git a/examples/using-profiler.php b/examples/using-profiler.php
index d67a4f0f..6ee38396 100644
--- a/examples/using-profiler.php
+++ b/examples/using-profiler.php
@@ -11,7 +11,7 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
}
-dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
'profiler' => [
@@ -22,7 +22,7 @@ dibi::connect([
// execute some queries...
for ($i = 0; $i < 20; $i++) {
- $res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] < ?', $i);
+ $res = $dibi->query('SELECT * FROM [customers] WHERE [customer_id] < ?', $i);
}
// display output
diff --git a/examples/using-substitutions.php b/examples/using-substitutions.php
index 5027da4f..aa871550 100644
--- a/examples/using-substitutions.php
+++ b/examples/using-substitutions.php
@@ -9,23 +9,23 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
}
-dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
]);
// create new substitution :blog: ==> wp_
-dibi::getSubstitutes()->blog = 'wp_';
+$dibi->getSubstitutes()->blog = 'wp_';
-dibi::test('SELECT * FROM [:blog:items]');
+$dibi->test('SELECT * FROM [:blog:items]');
// -> SELECT * FROM [wp_items]
// create new substitution :: (empty) ==> my_
-dibi::getSubstitutes()->{''} = 'my_';
+$dibi->getSubstitutes()->{''} = 'my_';
-dibi::test("UPDATE ::table SET [text]='Hello World'");
+$dibi->test("UPDATE ::table SET [text]='Hello World'");
// -> UPDATE my_table SET [text]='Hello World'
@@ -42,13 +42,13 @@ function substFallBack($expr)
// define callback
-dibi::getSubstitutes()->setCallback('substFallBack');
+$dibi->getSubstitutes()->setCallback('substFallBack');
// define substitutes as constants
define('SUBST_ACCOUNT', 'eshop_');
define('SUBST_ACTIVE', 7);
-dibi::test("
+$dibi->test("
UPDATE :account:user
SET name='John Doe', status=:active:
WHERE id=", 7
diff --git a/examples/using-transactions.php b/examples/using-transactions.php
index 7f46a52d..d3d2a8c4 100644
--- a/examples/using-transactions.php
+++ b/examples/using-transactions.php
@@ -9,28 +9,28 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
}
-dibi::connect([
+$dibi = new Dibi\Connection([
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
]);
echo "
Before
\n";
-dibi::query('SELECT * FROM [products]')->dump();
+$dibi->query('SELECT * FROM [products]')->dump();
// -> 3 rows
-dibi::begin();
-dibi::query('INSERT INTO [products]', [
+$dibi->begin();
+$dibi->query('INSERT INTO [products]', [
'title' => 'Test product',
]);
echo "
After INSERT
\n";
-dibi::query('SELECT * FROM [products]')->dump();
+$dibi->query('SELECT * FROM [products]')->dump();
-dibi::rollback(); // or dibi::commit();
+$dibi->rollback(); // or $dibi->commit();
echo "
After rollback
\n";
-dibi::query('SELECT * FROM [products]')->dump();
+$dibi->query('SELECT * FROM [products]')->dump();
// -> 3 rows again