Re: Send multiple SQL staments in one query
| From: | Seth Remington | Date: | Mon, 25 Nov 2002 13:38:04 +0000 |
| Subject: | Re: Send multiple SQL staments in one query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-125929@lists.php.net to get a copy of this message | ||
Miguel lópez dinaweb dpto. programación wrote:
Hi, I can't send multiple sql staments in one query, i always get an error saying that the sentece is incorrect, i thorw the sentece in a mysql console and works fine, i'm sepraing sentences with ; i try to separe using ;\n or ;\r\n but don't work Anyone can help me? :-) ________________________________________________________ Miguel López Sánchez ProgramadorHere's a function that I use to run multiple SQL statements at once - similar to running MySQL in batch mode. It relies on a semicolon to separate the SQL statements. function SendBatchQuery($db_host, $db_base, $db_user, $db_pw, $query) {Voz +34 902 014 945 E-mail: mlopez@dinaweb.com-------------------------------------------------------- Dinaweb Networks s.l. Rúa das Orfas 27 15703 Santiago de Compostela A Coruña Gz Sp ECCVoz +34 902 014 945 GMT+1E-mail: info@dinaweb.com -------------------------------------------------------- http://www.dinaweb.com http://www.dinahosting.comhttp://www.u-lo.com http://www.empregogalego.com________________________________________________________ Hi Miguel,
$message = "Connection with server $db_host failed";
mysql_connect($db_host, $db_user, $db_pw) or die($message);
$message = "Could not select database $db_base";
mysql_select_db($db_base) or die($message);
$array = explode(';', $query);
foreach($array as $value) {
if(!$result = mysql_query($value)) {
break;
}
}
return $result;
}
Enjoy,
Seth Remington
SaberLogic, LLC
661-B Weber Drive
Wadsworth, Ohio 44281
Phone: (330)335-6442
Fax: (330)336-8559