1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-04 21:28:02 +02:00

* added DibiTable

* new connection options: "result:objects" & "result:withtables"
* renamed DibiDriverInterface -> IDibiDriver, DibiVariableInterface -> IDibiVariable
This commit is contained in:
David Grudl
2008-01-15 03:43:03 +00:00
parent da0a239d6d
commit 5c045e58dc
21 changed files with 461 additions and 58 deletions

View File

@@ -10,6 +10,7 @@ try {
dibi::connect(array(
'driver' => 'sqlite',
'database' => 'sample.sdb',
'result:objects' => TRUE, // fetch rows as objects
));
echo 'OK';

View File

@@ -1,4 +1,4 @@
<h1>DibiVariableInterface example</h1>
<h1>IDibiVariable example</h1>
<?php
require_once '../dibi/dibi.php';

87
examples/dibi.table.php Normal file
View File

@@ -0,0 +1,87 @@
<h1>DibiTable demo</h1>
<pre>
<?php
require_once '../dibi/dibi.php';
copy('sample.sdb', 'sample_tmp.sdb');
dibi::connect(array(
'driver' => 'sqlite',
'database' => 'sample_tmp.sdb',
));
// table products
class Products extends DibiTable
{
// rely on autodetection...
// protected $name = 'products';
// protected $primary = 'product_id';
}
// autodetection: primary keys are customer_id, order_id, ...
DibiTable::$primaryMask = '%s_id';
// create table object
$products = new Products();
echo "Table name: $products->name\n";
echo "Primary key: $products->primary\n";
// Finds rows by primary key
foreach ($products->find(1, 3) as $row) {
...
}
// select all
$products->findAll()->dump();
// select all, order by title, product_id
$products->findAll('title', $products->primary)->dump();
// fetches single row with id 3
$row = $products->fetch(3);
// deletes row from a table
$count = $products->delete(1);
// deletes multiple rows
$count = $products->delete(array(1, 2, 3));
var_dump($count); // number of deleted rows
// update row #2 in a table
$data = (object) NULL;
$data->title = 'New title';
$count = $products->update(2, $data);
var_dump($count); // number of updated rows
// update multiple rows in a table
$count = $products->update(array(3, 5), $data);
var_dump($count); // number of updated rows
// inserts row into a table
$data = array();
$data['title'] = 'New product';
$id = $products->insert($data);
var_dump($id); // generated id
// is absolutely SQL injection safe
$key = '3 OR 1=1';
$products->delete($key);
// --> DELETE FROM [products] WHERE [product_id] IN ( 3 )