Advertisement
Guest User

Untitled

a guest
May 14th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. {"_" . $name})) { throw new ExtendedException("Cannot find member variable '" . $name . "' of class '" . __CLASS__ . "'."); } $this->{$name} = $value; } /** * Magical method to get the value of a member variable. * @param string $name The key of the member variable to return. * @return mixed The value of the member variable. */ public function __get($name) { if(!isset($this->{"_" . $name})) { throw new ExtendedException("Cannot find member variable '" . $name . "' of class '" . __CLASS__ . "'."); } return $this->{$name}; } /** * Overrides __clone() and throws an exception. */ public function __clone() { throw new ExtendedException("Cannot clone a singleton object of type " . __CLASS__ . "."); } /** * Returns a reference to the singleton class object. * @return mixed An object of type DB. */ public static function singleton() { if(!isset(DB::$_instance)) { self::$_instance = new DB(); } return self::$_instance; } /** * Open a connection to a MySQL Server. * @param string $host The database hostname. * @param string $username The database connection username. * @param string $password The database connection password. * @param string $database The database name. */ public function Connect($host = NULL, $username = NULL, $password = NULL, $database = NULL) { if($host) $this->_host = $host; if($username) $this->_username = $username; if($password) $this->_password = $password; if($database) $this->_database = $database; $this->_connection = mysql_connect($this->_host, $this->_username, $this->_password, $this->_database); if(!$this->_connection) { throw new DBException(mysql_error(), $this->_host, $this->_database, mysql_errno()); } if(!mysql_select_db($database, $this->_connection)) { throw new DBException(mysql_error(), $this->_host, $this->_database, mysql_errno()); } } /** * Executes a query. * @param string $query The query to be executed. * @return mixed The query results resource. */ public function Execute($query) { $result = mysql_query($query, $this->_connection); if(mysql_error($this->_connection)) { throw new DBException(mysql_error(), $this->_host, $this->_database, mysql_errno(), $query); } return $result; } /** * Gets the number of rows from a MySQL resource. * @param mixed $resource The resource to get the count of rows from. * @return int the number of rows in the resource. */ public function GetCount($resource) { return mysql_num_rows($resource); } /** * Retrieves a record from a MySQL resource. * @param mixed $resource The resource to retrieve the record from. * @param integer $type The type of array that is to be fetched. The default value is MYSQL_ASSOC. [optional] * @return array An associative array representing the fetched record. */ public function FetchRow($resource, $type = MYSQL_ASSOC) { return mysql_fetch_array($resource, $type); } /** * Get the ID generated from the previous INSERT operation. * @return int The generated id. */ public function GetLastID() { return mysql_insert_id($this->_connection); } /** * Get number of affected rows in previous MySQL operation. * @return int The number of affected rows on success, and -1 if the last query failed. */ public function GetAffectedRows() { return mysql_affected_rows($this->_connection); } } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement