Logo Blogo

Zebra_Database, un wrapper PHP per MySQL

Pubblicato: 28 gen 2011 da Lpt on fire!

Zebra_Database

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)
);

?>

1 stelle2 stelle3 stelle4 stelle5 stelle (nessun voto)
condividi condividi
1 commento

Commenti dei lettori

(Inserisci un commento - Nascondi commenti anonimi)
  • Profilo di zuk

    zuk

    29 gen 2011 - 15:46 - #1
    0 punti
    Up Down

    Molto interessante

L'email è richiesta ma non verrà mostrata ai visitatori.
Commenta questo articolo

Registrati per riservare il tuo nickname preferito su tutti i blog di Blogo e per caricare il tuo avatar. Se sei già registrato, effettua il login per usare il tuo nickname.

Si No
I commenti sono sottoposti alle linee guida per la moderazione.

Anteprima del commento