2010-09-14

Dibi es una libreria para poder abstraerce de la base de datos.


Dibi es una libreria para poder abstraerce de la base de datos.
Link a la librer DIBI


<?php
// connect to database
dibi::connect(array(
'driver' => 'mysql',
'host' => 'localhost',
'username' => 'root',
'password' => '***',
));
// select, insert, update
dibi::query('SELECT * FROM [table] WHERE [id] = %i', $id);
$arr = array(
'name' => 'John',
'is_admin' => TRUE,
);
dibi::query('INSERT INTO [table]', $arr);
// INSERT INTO `table` (`name`, `is_admin`) VALUES ('John', 1)
dibi::query('UPDATE `table` SET ', $arr, 'WHERE `id`=%i', $x);
// UPDATE `table` SET `name`='John', `is_admin`=1 WHERE `id` = 123
// getting results
$result = dibi::query('SELECT * FROM `table`');
$value = $result->fetchSingle(); // single value
$all = $result->fetchAll(); // all rows
$assoc = $result->fetchAssoc('id'); // all rows as associative array
$pairs = $result->fetchPairs('customerID', 'name'); // all rows as key => value pairs
// iterating
foreach ($result as $n => $row) {
print_r($row);
}
?>
view raw DEMO-DIBI.php hosted with ❤ by GitHub

No hay comentarios: