note 49629 deleted from function.mysql-query by philip
| From: | philip@php.net | Date: | Wed, 06 Apr 2005 17:58:34 +0000 |
| Subject: | note 49629 deleted from function.mysql-query by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-87599@lists.php.net to get a copy of this message | ||
Note Submitter: jordi dot alcantara at gmail dot com
----
Based on Predrag Supurovic mysql_exec_batch function.
Useful if your queries contains html code with ; characters
The input must be an array() with queries inserted with array_unshift() or similar. $p_query acts as
an STACK!!.
function mysql_exec_batch2 ($p_query, $p_transaction_safe = true) {
if (!is_array($p_query)){
echo("<br><br><b>Error: input is not
ARRAY</b><br><br>\n");////////////////////
return;
}
if ($p_transaction_safe)
array_push($p_query,'START TRANSACTION');
while(sizeof($p_query)>0){
$query= array_pop($p_query);
$result= mysql_query($query)
or die("function mysql_exec_batch ERROR ".mysql_error());
if($result==0)
break;
}
if($p_transaction_safe){
if ($result!=0){
$result= mysql_query('COMMIT');
}
else{
$result= mysql_query('ROLLBACK');
}
}
return $result;
}