View Single Post
Old 12-09-2002, 07:30 PM   #2 (permalink)
sdeming
Code Monkey
 
Join Date: Jul 2002
Location: Michigan
Posts: 85
sdeming is on a distinguished road
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($fd32768);
    
$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...
__________________
Scott
B4 09 BA 09 01 CD 21 CD 20 53 63 6F 74 74 24
sdeming is offline   Reply With Quote