|
Posted by Tom on 09/29/50 11:37
Thanks for the responses. I finally found this:
http://www.php.net/manual/en/function.mysql-query.php#37870
The PHP manual isn't explicit on the point, though it does note, "The
query string should not end with a semicolon."
Below is my variation on the function provided in the comment:
/* fx mysql_query_batch
source: http://www.php.net/manual/en/function.mysql-query.php#31381
*************************************************/
function mysql_query_batch($query, $as_transaction=TRUE)
{
// *** DATA
# internal
$_SPLIT = array();
$_statement = '';
# return
$query_result = 0;
// *** MANIPULATE
# transaction-safe query
if ( $as_transaction )
{
$query = 'START TRANSACTION;' . $query . '; COMMIT;';
}
# split query
$_SPLIT = preg_split("/[;]+/", $query);
# process statements one-by-one
foreach ( $_SPLIT as $_statement )
{
$_statement = trim($_statement);
if ( !empty($_statement) )
{
# try query
$query_result = mysql_query($_statement);
# catch
if ( !$query_result )
{
trigger_error('MySQL error number '.mysql_errno().': '.mysql_error());
break;
}
}
}
// *** RETURN
return $query_result;
} # end Fx
/*______________________________________________*/
Not extensively tested, but it's met my demands thus far.
Incidentally, I dug out the phpmyadmin function -- it parses the
textarea post character-by-character and splits up the statements.
[Back to original message]
|