JDatabaseMySQL/queryBatch
From Joomla! Documentation
< API15:JDatabaseMySQLRevision as of 17:15, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description===
Execute a batch query
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>...)
Revision as of 17:15, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description===
Execute a batch query
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>...)
The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Execute a batch query
Template:Description:JDatabaseMySQL/queryBatch
Syntax[edit]
queryBatch($abort_on_error=true, $p_transaction_safe=false)
Parameter Name | Default Value | Description |
---|---|---|
$abort_on_error | true | |
$p_transaction_safe | false |
Returns[edit]
mixed A database resource if successful, FALSE if not.
Defined in[edit]
libraries/joomla/database/database/mysql.php
Importing[edit]
jimport( 'joomla.database.database.mysql' );
Source Body[edit]
function queryBatch( $abort_on_error=true, $p_transaction_safe = false)
{
$this->_errorNum = 0;
$this->_errorMsg = '';
if ($p_transaction_safe) {
$this->_sql = rtrim($this->_sql, "; \t\r\n\0");
$si = $this->getVersion();
preg_match_all( "/(\d+)\.(\d+)\.(\d+)/i", $si, $m );
if ($m[1] >= 4) {
$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;';
}
}
$query_split = $this->splitSql($this->_sql);
$error = 0;
foreach ($query_split as $command_line) {
$command_line = trim( $command_line );
if ($command_line != '') {
$this->_cursor = mysql_query( $command_line, $this->_resource );
if ($this->_debug) {
$this->_ticker++;
$this->_log[] = $command_line;
}
if (!$this->_cursor) {
$error = 1;
$this->_errorNum .= mysql_errno( $this->_resource ) . ' ';
$this->_errorMsg .= mysql_error( $this->_resource )." SQL=$command_line <br />";
if ($abort_on_error) {
return $this->_cursor;
}
}
}
}
return $error ? false : true;
}
[Edit See Also] Template:SeeAlso:JDatabaseMySQL/queryBatch
Examples[edit]
<CodeExamplesForm />