Dibi es una libreria para poder abstraerce de la base de datos.
Link a la librer DIBI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
?> |
No hay comentarios:
Publicar un comentario