\n"; print nl2br(htmlentities(implode($readme, ' '))); print "
Continue
\n"; print "
\n"; exit; } } // list all sql files in this directory for the user to choose from if(!$filename) { print "Select an SQL file to install."; } // look like we've decided on a file else { // read in the sql file and parse it into a form if(!$action) { $sql_file = file($filename); $sql_statements = array(); // create a new array containing just the lines we want. foreach($sql_file as $k=>$v) { // get rid of whitespace $sql = trim($v); // no comments, please if(substr($sql, 0, 1) == '#') { continue; } // no blank lines if(!$sql) { continue; } // insert the current sql line into a buffer $cur_sql .= $sql . ' '; // get the ending character. if it's a ';' then we have a full statement, otherwise keep appending until we do. if(substr($sql, -1, 1) == ';') { $sql_statements[] = substr(trim($cur_sql), 0, -1); $cur_sql = ''; } } // ok, we got our new array 'sql_statements' containing a full sql statement per element // now, let's display them in a form to allow modification before commiting print "Check over the following SQL statements and make sure they are correct for your server. If so, click the "Commit" button.

\n"; print "
\n"; print "\n"; print "\n"; print "\n"; foreach($sql_statements as $k=>$v) { print "" . $k . ":

\n"; } print ""; print "
"; } // commit the changes to the database else { foreach($sql_statements as $k=>$v) { $result = mysql_query(stripslashes($v)); if(!$result) { print "Error: the following SQL statement didn't work.
\n"; print mysql_error() . '

'; print "
\n" . htmlentities(stripslashes($v)) . "\n
"; print "
"; } } print "

SQL Database Updated!

"; } } ?>