
Zebra_Database è un wrapper object-oriented per connessioni a database MySQL da PHP.
Il progetto è composto da un solo file e fornisce un’interfaccia più intuitiva e semplice da utilizzare per la gestione della vostra base di dati. La classe fornisce anche un sistema di debugging con informazioni dettagliate sulle query eseguite, il loro tempo di esecuzione, messaggi d’errore ed altro ancora. Utilizza automaticamente EXPLAIN per ogni SELECT e viene effettuato l’escape delle stringhe per evitare problemi di sicurezza. È rilasciato sotto licenza LGPL.
Dopo il salto potete trovare alcuni esempi d’uso.
<?php
require ‘path/to/Zebra_Database.php’;
$db = new Zebra_Database();
// turn debugging on
$db->debug = true;
$db->connect(‘host’, ‘username’, ‘password’, ‘database’);
// code goes here
// this should always be present at the end of your scripts;
// whether it should output anything should be controlled by the $debug property
$db->show_debug_console();
?>
SELECT statement
<?php
// $criteria will be escaped and enclosed in grave accents, and will
// replace the corresponding ? (question mark) automatically
$db->select(
‘column1, column2′,
‘table’,
‘criteria = ?’,
array($criteria)
);
// after this, one of the “fetch” methods can be run:
// to fetch all records to one associative array
$records = $db->fetch_assoc_all();
// or fetch records one by one, as associative arrays
while ($row = $db->fetch_assoc()) {
// do stuff
}
?>
INSERT statement
<?php
$db->insert(
‘table’,
array(
‘column1′ => $value1,
‘column2′ => $value2,
)
);
?>
UPDATE statement
<?php
// $criteria will be escaped and enclosed in grave accents, and will
// replace the corresponding ? (question mark) automatically
$db->update(
‘table’,
array(
‘column1′ => $value1,
‘column2′ => $value2,
),
‘criteria = ?’,
array($criteria)
);
?>
zuk
29 gen 2011 - 15:46 - #1Molto interessante