PHP Classes
elePHPant
Icontem

Zebra Database: MySQL database access wrapper library

Recommend this page to a friend!
  Info   View files Example   View files View files (31)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2016-01-12 (9 months ago) RSS 2.0 feedStarStarStar 54%Total: 2,064 All time: 1,845 This week: 1,081Up
Version License PHP version Categories
zebra-database 2.9.0GNU Lesser Genera...5.0.4Databases
Description Author

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 intuitive and fun to use than PHP's default ones.

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 automatically escaping strings.

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

Picture of Stefan Gabos
Name: Stefan Gabos <contact>
Classes: 11 packages by
Country: Romania Romania
Innovation award
Innovation award
Nominee: 1x

Details

Zebra_Database

An advanced, compact and lightweight MySQL database wrapper library, built around PHP's mysqli extension

It provides methods for interacting with MySQL databases that are more powerful and intuitive 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.

Features

  • it uses the mysqli extension for communicating with the database instead of the old mysql extension, which is officially deprecated as of PHP v5.5.0 and will be removed in the future; again, this is not a wrapper for the PDO extension which is already a wrapper in itself
  • offers lots of powerful methods for easier interaction with MySQL
  • provides a better security layer by encouraging the use of prepared statements, where parameters are automatically escaped
  • provides a very detailed debugging interface with lots of useful information about executed queries; it also automatically EXAPLAIN?s each SELECT query
  • supports caching of query results to disk or to a memcache server
  • has comprehensive documentation
  • code is heavily commented and generates no warnings/errors/notices when PHP?s error reporting level is set to E_ALL

Requirements

PHP 5+ with the mysqli extension activated, 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]

How to use

Connect to a database


<?php

require 'path/to/Zebra_Database.php';

$db = new Zebra_Database();

// turn debugging on
$db->debug = true;

// set relative path to parent of public folder from $_SERVER'DOCUMENT_ROOT'
// no leading slash
// ie: http://example.com/vendor/stefangabos/zebra_database/public/css/database.css
$db->resource_path = 'vendor/stefangabos/zebra_database';

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

?>

Visit the project's homepage for more information.

  Files folder image Files  
File Role Description
Files folder imageexamples (3 files)
Files folder imagelanguages (4 files)
Files folder imagepublic (1 file, 2 directories)
Accessible without login Plain text file changelog.txt Data Changelog
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file documentation.txt Data Documentation
Accessible without login Plain text file index.html Conf. Prevent directory listing
Accessible without login Plain text file license.txt Lic. License
Accessible without login Plain text file README.md Data Auxiliary data
Accessible without login Plain text file readme.txt Data Readme File
Plain text file Zebra_Database.php Class Class source

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file example.php Example Example script
  Accessible without login HTML file index.html Conf. Prevent directory listing
  Accessible without login Plain text file install.txt Doc. Documentation

  Files folder image Files  /  languages  
File Role Description
  Accessible without login Plain text file english.php Data Language file
  Accessible without login Plain text file german.php Aux. Auxiliary script
  Accessible without login HTML file index.html Conf. Prevent directory listing
  Accessible without login Plain text file russian.php Aux. Auxiliary script

  Files folder image Files  /  public  
File Role Description
Files folder imagecss (12 files)
Files folder imagejavascript (3 files)
  Accessible without login HTML file index.html Conf. Prevent directory listing

  Files folder image Files  /  public  /  css  
File Role Description
  Accessible without login Image file affected.png Icon Image file
  Accessible without login Image file backtrace.png Icon Image file
  Accessible without login Image file cache.png Icon Image file
  Accessible without login Image file clock.png Icon Image file
  Accessible without login Image file close.png Icon Image file
  Accessible without login Plain text file database.css Aux. CSS file
  Accessible without login Image file db.gif Icon Image file
  Accessible without login Image file explain.png Icon Image file
  Accessible without login HTML file index.html Conf. Prevent directory listing
  Accessible without login Plain text file license.txt Lic. License
  Accessible without login Image file records.png Icon Image file
  Accessible without login Image file top.png Icon Image file

  Files folder image Files  /  public  /  javascript  
File Role Description
  Accessible without login Plain text file database.js Data JavaScript file (minified)
  Accessible without login Plain text file database.src.js Data JavaScript file
  Accessible without login HTML file index.html Conf. Prevent directory listing

 Version Control Unique User Downloads Download Rankings  
 100%
Total:2,064
This week:0
All time:1,845
This week:1,081Up
 User Ratings  
 
 All time
Utility:75%StarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:-
Examples:83%StarStarStarStarStar
Tests:-
Videos:-
Overall:54%StarStarStar
Rank:1697