PHP Classes
Icontem

File: DATA/MySQL5/Access.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/Access.php  
File: DATA/MySQL5/Access.php
Role: Class source
Content type: text/plain
Description: This class provides basic interaction with a MySQL5 database.
Class: DATA
Access data stored in MySQL tables like arrays
 

Contents

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

/**
 * This class provides basic interaction with a MySQL5 database.
 * 
 * Access functions called from the Database object are proxied
 * to this object.
 * @see DATA_MySQL5_Database::__call()
 */
class DATA_MySQL5_Access {
    
/**
     * Connects to a MySQL5 database.
     * @link http://php.net/mysql_connect
     * @param string $server Optional. Server address.
     * @param string $username Optional. User name.
     * @param string $password Optional. Password.
     * @param bool $newLink Optional. Force a second link to be opened in the case
     *                        there is already a connection with the same parameters.
     * @param int $clientFlags Optional.
     * @return resource The opened connection.
     */
    
static public function connect() {
        
$args func_get_args();        
        return 
call_user_func_array('mysql_connect'$args);
    }
    
    
/**
     * Changes the current schema in the currently connected MySQL5 database
     * @param string $schema The schema name.
     * @param resource $link Optional. A different link to an opened MySQL5 connection.
     * @return bool True on success, false on failure.
     */
    
static public function selectSchema($schema) {
        
$args func_get_args();        
        return 
call_user_func_array('mysql_select_db'$args);
    }
    
    
/**
     * Executes a query.
     * Throws a {@link DATA_MySQL5_Error DATA_MySQL5_Error exception} on failure.
     * @param string $sql The query in sql.
     * @return resource An object/resource representing the query results.
     */
    
static public function query($sql) {
        
$query mysql_query($sql);
        if (!
$querythrow new DATA_MySQL5_Error();
        return 
$query;
    }
    
    
/**
     * Returns the last auto numeric id inserted.
     * @return int The id.
     */
    
static public function getInsertID() {
        return 
mysql_insert_id();
    }
    
    
/**
     * Free the memory occupied by a query result.
     * @param resource $query An object/resource representing the query results.
     * @return bool True on success, false on failure.
     */
    
static public function freeResult($query) {
        return 
mysql_free_result($query);
    }
    
    
/**
     * Returns a numerically indexed array with the next results in the
     * provided query object/resource.
     * 
     * @param resource $query The query results object/resource.
     * @return array The next row in the results.
     */
    
static public function fetchRow($query) {
        return 
mysql_fetch_row($query);
    }
    
    
/**
     * Returns an associative array with the next results in the
     * provided query object/resource.
     * @param resource $query The query results object/resource.
     * @return array The next row in the results.
     */
    
static public function fetchAssoc($query) {
        return 
mysql_fetch_assoc($query);
    }
    
    
/**
     * Get field data from query result.
     * @param resource $query The query results object/resource.
     * @param int $row The row number.
     * @param int|string $field Optional. The field. First field if omitted.
     * @return string The field data.
     */
    
static public function result($query$row) {
        
$args func_get_args();        
        return 
call_user_func_array('mysql_result'$args);
    }
    
/**
     * Moves the result pointer.
     * @param resource $query An object/resource representing the query results.
     * @param int $row The row number.
     * @return bool True on success, false on failure.
     */
    
static public function dataSeek($query$row) {
        return 
mysql_data_seek($query$row);
    }
    
    
/**
     * Returns the error message of the last error occurred.
     * @param resource $link Optional. Link to an open database connection.
     * @return string The error message.
     */
    
static public function error() {
        
$args func_get_args();        
        return 
call_user_func_array('mysql_error'$args);
    }
    
    
/**
     * Returns the error number of the last error occurred.
     * @param resource $link Optional. Link to an open database connection.
     * @return int The error number.
     */
    
static public function errorNo() {
        
$args func_get_args();        
        return 
call_user_func_array('mysql_errno'$args);
    }
    
    
/**
     * Escapes a string to be used between single quotes in a sql query.
     * @param string $string The string needing escaping.
     * @return string The escaped string.
     */
    
static public function escape($string) {
        return 
mysql_real_escape_string($string);
    }
    
    
/**
     * Prepares data to be used in a sql query.
     * @param mixed $data The data.
     * @return string The string representing the data in a sql query.
     */
    
static public function prepareData($data) {
        if (
$data === null || ($data instanceof DATA_SQLType && $data->isNull())) {
            return 
'NULL';
        } else {
            return 
"'" self::escape((string)$data) . "'";
        }
    }
}
?>

 
  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