PHP Classes

File: DATA/MySQL5/Database.php

Recommend this page to a friend!
  Classes of Martin Alterisio   DATA   DATA/MySQL5/Database.php   Download  
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
Author: By
Last change: v0.8 - disabling of inboxing of sql data types is available through property ->withoutInboxing
Date: 17 years ago
Size: 3,040 bytes
 

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