Source code for file /joomla/database/database.php
Documentation is available at database.php
* @version $Id: database.php 9870 2008-01-05 10:56:58Z eddieajau $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* Database connector class
* @package Joomla.Framework
* The database driver name
* The database error number
* The database error message
* The prefix used on all database tables
* The limit for the query
* The for offset for the limit
* The number of queries performed by the object instance
* The null/zero date string
* Quote for named objects
* The fields that are to be quote
* Database object constructor
* @param array List of options used to configure the connection
// Determine utf-8 support
//Set charactersets (needed for MySQL 4.1.2+)
// Register faked "destructor" in PHP4 to close all connections we might have made
* Returns a reference to the global Database object, only creating it
* if it doesn't already exist.
* The 'driver' entry in the parameters array specifies the database driver
* to be used (defaults to 'mysql' if omitted). All other parameters are
* database driver dependent.
* @param array Parameters to be passed to the database driver
* @return JDatabase A database object
if (!isset
( $instances )) {
if (empty($instances[$signature]))
$database =
array_key_exists('database', $options) ?
$options['database'] :
null;
$path =
dirname(__FILE__
).
DS.
'database'.
DS.
$driver.
'.php';
$error =
JError::raiseError( 500, JTEXT::_('Unable to load Database Driver:') .
$driver);
$adapter =
'JDatabase'.
$driver;
$instance =
new $adapter($options);
if ( $error =
$instance->getErrorMsg() )
$error =
JError::raiseError( 500, JTEXT::_('Unable to connect to the database:') .
$error);
$instances[$signature] =
& $instance;
return $instances[$signature];
* Database object destructor
* Get the database connectors
* @return array An array of available session handlers
jimport('joomla.filesystem.folder');
foreach($handlers as $handler)
$class =
'JDatabase'.
ucfirst($name);
require_once(dirname(__FILE__
).
DS.
'database'.
DS.
$name.
'.php');
* Test to see if the MySQLi connector is available
* @return boolean True on success, false otherwise.
* Determines if the connection to the server is active.
* Custom settings for UTF support
* Adds a field or array of field names to the list that are to be quoted
* @param mixed Field name or array of names
* Checks if field name needs to be quoted
* @param string The field name
* Sets the debug level on or off
* @param int 0 = off, 1 = on
function debug( $level ) {
* Get the database UTF-8 support
* @return int The error number for the most recent query
* @return string The error message for the most recent query
* Get a database escaped string
* @param string The string to be escaped
* @param boolean Optional parameter to provide extra escaping
* Get a database error log
* Get the total number of queries made
* Quote an identifier name (field, table, etc)
* @return string The quoted name
return $q{0} .
$s .
$q{1};
* Get the database table prefix
* @return string The database prefix
* Get the database null date
* @return string Quoted null/zero date string
* Sets the SQL query string for later execution.
* This function replaces a string identifier <var>$prefix</var> with the
* string held is the <var>_table_prefix</var> class variable.
* @param string The SQL query
* @param string The offset to start selection
* @param string The number of results to return
* @param string The common table prefix
function setQuery( $sql, $offset =
0, $limit =
0, $prefix=
'#__' )
* This function replaces a string identifier <var>$prefix</var> with the
* string held is the <var>_table_prefix</var> class variable.
* @param string The SQL query
* @param string The common table prefix
$ip =
strpos($sql, $prefix, $startPos);
$j =
strpos( $sql, "'", $startPos );
$k =
strpos( $sql, '"', $startPos );
if (($k !==
FALSE) &&
(($k <
$j) ||
($j ===
FALSE))) {
// quote comes first, find end of quote
$k =
strpos( $sql, $quoteChar, $j );