DALMP

Database Abstraction Layer for MySQL using PHP

0% fat and extremely easy to use. Only connect to database when needed.

Download

Clone the repository:

git clone git://github.com/nbari/DALMP.git dalmp

Details

  • Redis.io support.
  • Memcache single or multiple hosts and socket support.
  • APC support (http://pecl.php.net/package/APC).
  • Group caching cache by groups and flush by groups or individual keys.
  • Disk cache support.
  • Prepared statements ready, support dynamic building queries, auto detect types (i,d,s,b).
  • Secure connections with SSL.
  • SQLite3 Encryption (http://sqlcipher.net).
  • Ability to use different cache types at the same time.
  • Simple store of session on database (mysql/sqlite) or a cache like redis/memcache/apc.
  • Easy to use/install/adapt.
  • Nested Transactions (SAVEPOINT / ROLLBACK TO SAVEPOINT).
  • Support connections via unix_sockets.
  • SQL queues.
  • Export to CSV.
  • Trace/measure everything enabling the debugger by just setting something like $db->debug(1).
  • Works outof the box with Cloud databases like Xeround & Amazon RDS.
  • Lazy database connection. Connect only when needed.

Requirements

  • PHP
  • To use the cache features you need either the redis, memcache or APC extensions compiled, otherwise disk cache will be used
    • Redis extension - http://github.com/nicolasff/phpredis
    • Memcache PECL extencsion - http://pecl.php.net/package/memcache
    • APC PECL extension - http://pecl.php.net/package/APC
  • If you want to store session encrypted then you need SQLite3 Encryption (http://sqlcipher.net).
  • DALMP does not use PDO, so do not worry if your PHP does not have the pdo extension.
  • A MySQL server to connect via host/socket

On FreeBSD you can install DALMP from ports: /usr/ports/databases/dalmp

Examples

DALMP takes the parameters from a DSN (database source name) so before you can start using it you need to define these values as shown in the self explanatory example below.

require_once 'dalmp.php';
// DSN format: charset://username:password@host:port/database
$db = new DALMP('utf8://root:'.rawurlencode('pass-?/:word').'@mysql.localbox.org:3306/mydatabase');
$rs = $db->FetchMode('ASSOC')->PGetAll('SELECT id,name FROM users WHERE id=?',3);

Example using memcache, notice that the cache parameters are the DSN query

require_once 'dalmp.php';
// DSN format: charset://username:password@host:port/database?(type:host:port:compression)
$db = new DALMP('utf8://root:'.rawurlencode('pass-?/:word').'@mysql.localbox.org:3306/mydatabase?memcache:127.0.0.1:11211:1');
$rs = $db->FetchMode('ASSOC')->PCacheGetAll('SELECT id,name FROM users WHERE id=?',3);

Example storing Session on DB

require_once 'dalmp.php';
$db = new DALMP('utf8://root:'.rawurlencode('pass-?/:word').'@mysql.localbox.org:3306/mydatabase');
$sessions = new DALMP_Sessions($db);
if ((mt_rand() % 10) == 0) {
$sessions->regenerate_id(4);
}
$_SESSION['test'] = 1 + @$_SESSION['test'];

Bugs / suggestions / comments

If you found a bug of have any other inquiries please use the the DALMP group at :https://groups.google.com/group/dalmp


A great amount of time has been spent creating, crafting and maintaining this software, please consider donating.

Donating helps ensure continued support, development and availability.

dalmp