Reply to Re: using heredoc for SQL statements

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация