Deprecated: Assigning the return value of new by reference is deprecated in /home/bluestat/public_html/source/index.php on line 477
ISSO - Blob - ViewGit - Blue Static
<?php
/*=====================================================================*\
|| ###################################################################
|| # Blue Static ISSO Framework
|| # Copyright (c)2005-2008 Blue Static
|| #
|| # This program is free software; you can redistribute it and/or modify
|| # it under the terms of the GNU General Public License as published by
|| # the Free Software Foundation; version 2 of the License.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|| # more details.
|| #
|| # You should have received a copy of the GNU General Public License along
|| # with this program; if not, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/

/**
 * MySQL Database Layer (DbMySql.php)
 *
 * @package	ISSO
 */

require_once(ISSO . '/Db.php');

/**
 * MySQL Database Layer
 *
 * This framework is a function wrapper for MySQL functions so we can have
 * better error reporting and query reporting.
 *
 * @author		Blue Static
 * @copyright	Copyright (c)2005 - 2008, Blue Static
 * @package		ISSO
 *
 */
class BSDbMySql extends BSDb
{
	/**
	 * Wrapper: mysql_connect
	 */
	protected function _connect($server, $user, $password, $database)
	{
		$link = @mysql_connect($server, $user, $password, true);
		if ($link)
		{
			$this->_selectDb($database, $link);
		}

		return $link;
	}

	/**
	 * Opens a connection to the specified database name
	 *
	 * @param	string	Database name
	 * @param	integer	DB-Link
	 */
	private function _selectDb($database, $link)
	{
		if (!mysql_select_db($database, $link))
		{
			throw new BSDbException($this->_errorString(), $this->_errorNumber(), 'Cannot use the database ' . $database);
		}
	}

	/**
	 * Wrapper: mysql_query
	 */
	protected function _query($string)
	{
		return mysql_query($string, $this->dblink);
	}

	/**
	 * Wrapper: mysql_escape_string
	 */
	protected function _escapeBinary($binary)
	{
		return mysql_escape_string($binary);
	}

	/**
	 * Wrapper: mysql(_real)_escape_string
	 */
	protected function _escapeString($string)
	{
		if (function_exists('mysql_real_escape_string'))
		{
			return @mysql_real_escape_string($string, $this->dblink);
		}
		else
		{
			return @mysql_escape_string($string);
		}
	}

	/**
	 * Not supported: unescape binary string
	 */
	protected function _unescapeBinary($string)
	{
		return $string;
	}

	/**
	 * Wrapper: mysql_insert_id
	 */
	protected function _insertId()
	{
		return mysql_insert_id($this->dblink);
	}

	/**
	 * Wrapper: mysql_affected_rows
	 */
	protected function _affectedRows($result)
	{
		return mysql_affected_rows($this->dblink);
	}

	/**
	 * Starts a database transaction
	 */
	public function begin()
	{
		$this->query("BEGIN WORK");
	}

	/**
	 * Reverts a transaction back to a given savepoint
	 */
	public function rollback()
	{
		$this->query("ROLLBACK");
	}

	/**
	 * Commits a database transaction
	 */
	public function commit()
	{
		$this->query("COMMIT");
	}

	/**
	 * Returns the error number
	 *
	 * @return	integer	Error number
	 */
	public function _errorNumber()
	{
		return mysql_errno($this->dblink);
	}

	/**
	 * Returns the error string
	 *
	 * @return	string	Error string
	 */
	public function _errorString()
	{
		return mysql_error($this->dblink);
	}
}

/**
 * Database Result
 *
 * This class holds result information for a database result
 *
 * @author		rsesek
 * @copyright	Copyright (c)2005 - 2008, Blue Static
 * @package		ISSO
 *
 */
class BSDbMySqlResult extends BSDbResult
{
	/**
	 * Wrapper: mysql_fetch_assoc
	 */
	protected function _fetchAssocArray($result)
	{
		return mysql_fetch_assoc($result);
	}

	/**
	 * Wrapper: mysql_fetch_row
	 */
	protected function _fetchRowArray($result)
	{
		return mysql_fetch_row($result);
	}

	/**
	 * Wrapper: mysql_fetch_object
	 */
	public function _fetchObject($result)
	{
		return mysql_fetch_object($result);
	}

	/**
	 * Wrapper: mysql_free_result
	 */
	protected function _freeResult($result)
	{
		mysql_free_result($result);
	}

	/**
	 * Wrapper: mysql_num_rows
	 */
	protected function _numRows($result)
	{
		return mysql_num_rows($result);
	}
}

?>