Source code for file /joomla/database/database/mysql.php
Documentation is available at mysql.php
* @version $Id: mysql.php 6757 2007-03-03 00:47:05Z CoolAcid $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 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
* @package Joomla.Framework
/** @var string The database driver name */
/** @var string The null/zero date string */
/** @var string Quote for named objects */
* Database object constructor
* @param string Database host
* @param string Database user name
* @param string Database user password
* @param string Database name
* @param string Common prefix for all tables
function __construct( $host=
'localhost', $user, $pass, $db=
'', $table_prefix=
'')
// perform a number of fatality checks, then die gracefully
$this->_errorMsg =
'The MySQL adapter "mysql" is not available.';
$this->_errorMsg =
'Could not connect to MySQL';
$this->_errorMsg =
'Could not connect to database';
// if running mysql 5, set sql-mode to mysql40 - thereby circumventing strict mode problems
$this->setQuery( "SET sql_mode = 'MYSQL40'" );
parent::__construct($host, $user, $pass, $db, $table_prefix);
* Database object destructor
return ($verParts[0] ==
5 ||
($verParts[0] ==
4 &&
$verParts[1] ==
1 && (int)
$verParts[2] >=
2));
* Custom settings for UTF support
//mysql_query("SET CHARACTER SET utf8",$this->_resource);
* Get a database escaped string
* @return mixed A database resource if successful, FALSE if not.
* @return int The number of affected rows in the previous operation
* @return mixed A database resource if successful, FALSE if not.
function queryBatch( $abort_on_error=
true, $p_transaction_safe =
false)
if ($p_transaction_safe) {
$this->_sql =
'START TRANSACTION;' .
$this->_sql .
'; COMMIT;';
} else if ($m[2] >=
23 &&
$m[3] >=
19) {
$this->_sql =
'BEGIN WORK;' .
$this->_sql .
'; COMMIT;';
} else if ($m[2] >=
23 &&
$m[3] >=
17) {
$this->_sql =
'BEGIN;' .
$this->_sql .
'; COMMIT;';
foreach ($query_split as $command_line) {
$command_line =
trim( $command_line );
if ($command_line !=
'') {
return $error ?
false :
true;
if (!($cur =
$this->query())) {
$buffer =
'<table id="explain-sql">';
$buffer .=
'<thead><tr><td colspan="99">'.
$this->getQuery().
'</td></tr>';
foreach ($row as $k=>
$v) {
$buffer .=
'<th>'.
$k.
'</th>';
$buffer .=
'</thead><tbody><tr>';
foreach ($row as $k=>
$v) {
$buffer .=
'<td>'.
$v.
'</td>';
$buffer .=
'</tbody></table>';
* @return int The number of rows returned from the most recent query.
* This method loads the first field of the first row returned by the query.
* @return The value returned in the query or null if the query failed.
if (!($cur =
$this->query())) {
* Load an array of single field results into an array
if (!($cur =
$this->query())) {
$array[] =
$row[$numinarray];
* Fetch a result row as an associative array
if (!($cur =
$this->query())) {
* Load a assoc list of database rows
* @param string The field name of a primary key
* @return array If <var>key</var> is empty as sequential list of returned records.
if (!($cur =
$this->query())) {
$array[$row[$key]] =
$row;
* This global function loads the first row of a query into an object
if (!($cur =
$this->query())) {
* Load a list of database objects
* @param string The field name of a primary key
* @return array If <var>key</var> is empty as sequential list of returned records.
* If <var>key</var> is not empty then the returned array is indexed by the value
* the database key. Returns <var>null</var> if the query fails.
if (!($cur =
$this->query())) {
$array[$row->$key] =
$row;
* @return The first row of the query.
if (!($cur =
$this->query())) {
* Load a list of database rows (numeric column indexing)
* @param string The field name of a primary key
* @return array If <var>key</var> is empty as sequential list of returned records.
* If <var>key</var> is not empty then the returned array is indexed by the value
* the database key. Returns <var>null</var> if the query fails.
if (!($cur =
$this->query())) {
$array[$row[$key]] =
$row;
* Inserts a row into a table based on an objects properties
* @param string The name of the table
* @param object An object whose properties match table fields
* @param string The name of the primary key. If provided the object property is updated.
$fmtsql =
"INSERT INTO $table ( %s ) VALUES ( %s ) ";
if ($k[0] ==
'_') { // internal field
* Document::db_updateObject()
* @param [type] $updateNulls
function updateObject( $table, &$object, $keyName, $updateNulls=
true )
$fmtsql =
"UPDATE $table SET %s WHERE %s";
if( $k ==
$keyName ) { // PK not to be updated
$where =
$keyName .
'=' .
$this->Quote( $v );
$tmp[] =
$this->nameQuote( $k ) .
'=' .
$val;
* Assumes database collation in use by sampling one text field in one table
* @return string Collation in use
$this->setQuery( 'SHOW FULL COLUMNS FROM #__content' );
return $array['4']['Collation'];
return "N/A (mySQL < 4.1.2)";
* @return array A list of all the tables in the database
* @param array A list of table names
* @return array A list the create SQL for the tables
foreach ($tables as $tblval) {
foreach ($rows as $row) {
$result[$tblval] =
$row[1];
* @param array A list of table names
* @return array An array of fields by table
foreach ($tables as $tblval) {
$this->setQuery( 'SHOW FIELDS FROM ' .
$tblval );
foreach ($fields as $field) {
$result[$tblval][$field->Field] =
preg_replace("/[(0-9)]/",'', $field->Type );