I had trouble with some of the examples, but finally got it to work. I couldn't get the exec() method to work at all.
Thanks a lot for your suggestions!!
Here's my working function:
function sendquery( $db_host, $db_base, $db_user, $db_pw, $filename ) {
// THIS MAY NOT BE THE MOST EFFICIENT WAY, BUT IT WORKS :-)
GLOBAL $messages;
$mess = 'Connexion with server ' . $db_host . ' failed';
mysql_connect( $db_host, $db_user, $db_pw ) or die($mess);
mysql_select_db( $db_base ) or die($mess);
$fcontents = file($filename); // filename should include path like "../../stock/file.sql"
$i=0;
foreach ($fcontents as $value) { // take out comments in file:
if ($value{0} == "#") {
$fcontents[$i] = "\n";
}
echo $fcontents[$i]."<BR>";
$i++;
}
$filestring = implode("",$fcontents); // convert to large string and take out \n, parse back into array by ";"
$filestring = str_replace("\n","",$filestring);
$newcontents = explode(";",$filestring);
$i=0;
foreach ($newcontents as $value) {
echo $value."<BR>";
$error = mysql_query("$value");
if ($error == 1) {
// $messages .= "line $i good<BR>"; // uncomment for debugging
}else{
// $messages .= "line $i ERROR !!!!!!!!!!!!!!!!!!!!!!!!!!!<BR>"; // uncomment for debugging
}
$i++;
}
}