Mike, try this by executing:
PHP Code:
run_query_batch($dbhandle, "schema.sql");
The function:
PHP Code:
function run_query_batch($handle, $filename="")
{
// --------------
// Open SQL file.
// --------------
if (! ($fd = fopen($filename, "r")) ) {
die("Failed to open $filename: " . mysql_error() . "<br>");
}
// --------------------------------------
// Iterate through each line in the file.
// --------------------------------------
while (!feof($fd)) {
// -------------------------
// Read next line from file.
// -------------------------
$line = fgets($fd, 32768);
$stmt = "$stmt$line";
// -------------------------------------------------------------------
// Semicolon indicates end of statement, keep adding to the statement.
// until one is reached.
// -------------------------------------------------------------------
if (!preg_match("/;/", $stmt)) {
continue;
}
// ----------------------------------------------
// Remove semicolon and execute entire statement.
// ----------------------------------------------
$stmt = preg_replace("/;/", "", $stmt);
// ----------------------
// Execute the statement.
// ----------------------
mysql_query($stmt, $handle) ||
die("Query failed: " . mysql_error() . "<br>");
$stmt = "";
}
// ---------------
// Close SQL file.
// ---------------
fclose($fd);
}
sde??? Hrm...