PHP Classes
Icontem

File: DATA/MySQL5/Database.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Martin Alterisio  >  DATA  >  DATA/MySQL5/Database.php  
File: DATA/MySQL5/Database.php
Role: Class source
Content type: text/plain
Description: This class is the abstraction of a MySQL5 database implementing the array access behavior.
Class: DATA
Access data stored in MySQL tables like arrays
 

Contents

Class file image Download
<?php
/**
 * @package DATA_MySQL5
 */

/**
 * This class is the abstraction of a MySQL5 database implementing the
 * array access behavior.
 * 
 * Example:
 * <code>
 * // connect to MySQL
 * $DB->connect($server, $user, $pass);
 * // select database 
 * $DB->selectSchema($schema);
 * // access a table
 * $DB['table']...;
 * </code>
 * 
 * @todo Implement table existence check.
 */
class DATA_MySQL5_Database implements ArrayAccess {
    
/**
     * Disables inboxing in this object.
     * @var bool
     */
    
protected $inboxingDisabled;
    
    
/**
     * Constructor.
     */
    
public function __construct() {
        
$this->inboxingDisabled false;
    }
    
    
/**
     * isset(..) handler. Indicates if table exists in current schema.
     * Not implemented yet.
     * Will throw {@link DATA_NotImplemented DATA_NotImplemented exception}.
     * @param string $offset The table name.
     * @return bool True if table exists, false otherwise.
     */
    
public function offsetExists($offset) {
        
throw new DATA_NotImplemented("DATA_MySQL5_Database::offsetExists");
    }
    
    
/**
     * [..] handler. Returns a table object corresponding to the array offset.
     * Must be a valid table (won't be checked).
     * @param string $offset The table name.
     * @return DATA_MySQL5_Table The table object.
     */
    
public function offsetGet($offset) {
        
$table = new DATA_MySQL5_Table($offset);
        if (
$this->inboxingDisabled) {
            
$table $table->withoutInboxing;
        }
        return 
$table;
    }
    
    
/**
     * [..] = handler. Table creation is not available.
     * Will throw {@link DATA_ReadOnly DATA_ReadOnly exception}.
     */
    
public function offsetSet($offset$value) {
        
throw new DATA_ReadOnly();
    }
    
    
/**
     * unset(..) handler. Table dropping is not available.
     * Will throw {@link DATA_ReadOnly DATA_ReadOnly exception}.
     */
    
public function offsetUnset($offset) {
        
throw new DATA_ReadOnly();
    }
    
    
/**
     * Member property overloading.
     * 
     * withoutInboxing property returns a db object with inboxing of
     * mysql types disabled.
     * 
     * @param string $propname Property name.
     * @return mixed Property value.
     */
    
public function __get($propname) {
        if (
$propname == 'withoutInboxing') {
            
$newDB clone $this;
            
$newDB->inboxingDisabled true;
            return 
$newDB;
        }
        
throw new Exception("Undefined property: {$propname}");
    }
    
    
/**
     * Function call overload. Proxies the calls to the common database
     * functions, if present.
     * @see DATA_MySQL5_Access
     */
    
public function __call($methodName$arguments) {
        if (
is_callable(array('DATA_MySQL5_Access'$methodName))) {
            return 
call_user_func_array(array('DATA_MySQL5_Access'$methodName), $arguments);
        }
    }
}
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products