Download Latest Version zebra_database.2.7.zip (55.7 kB)
Email in envelope

Get an email when there's a new version of Zebra_Database

Home
Name Modified Size InfoDownloads / Week
readme.md 2012-01-07 3.8 kB
zebra_database.2.7.zip 2012-01-07 55.7 kB
zebra_database.2.2.zip 2011-03-05 52.3 kB
zebra_database.2.1.zip 2011-01-30 49.8 kB
zebra_database.2.0.zip 2011-01-24 45.8 kB
Totals: 5 Items   207.5 kB 0

Zebra_Database, a MySQL database wrapper written in PHP

Zebra_Database it is an advanced, compact (one-file only), lightweight, object-oriented MySQL database wrapper built upon PHP's MySQL extension. It provides methods for interacting with MySQL databases that are more powerful and intuitive to use than PHP's default ones.

It supports transactions and provides ways for caching query results either by saving cached data on the disk, or by using memcache.

The class provides a comprehensive debugging interface with detailed information about the executed queries: execution time, returned/affected rows, excerpts of the found rows, error messages, etc. It also automatically EXPLAIN's each SELECT query (so you don't miss those keys again!).

It encourages developers to write maintainable code and provides a better default security layer by encouraging the use of prepared statements, where parameters are automatically escaped.

Zebra_Database's code is heavily commented and generates no warnings/errors/notices when PHP's error reporting level is set to E_ALL.


Requirements

PHP 4.4.9+, MySQL 4.1.22+

For using memcache as caching method, PHP must be compiled with the memcache extension and, if memcache_compressed property is set to TRUE, needs to be configured with –with-zlib[=DIR]


Installation

Download the latest version, unpack it, and put it in a place accessible to your scripts.


How to use

Connect to a database

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

?>

A 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
}
?>

An INSERT statement

<?php

$db->insert(
    'table',
    array(
        'column1' => $value1,
        'column2' => $value2,
    )
);

?>

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

?>

Useful links

Documentation | Changelog | Comments

Source: readme.md, updated 2012-01-07