// ------------------------------------------ // Obtain from server - a list of all existing databases on the server // ------------------------------------------ recreate_existing_databases_array($dblink); // --> $_SESSION["existing_databases"] // ------------------------------------------ // If have selected a DB application to work with: // ------------------------------------------ if (!empty($query)) { // ---------------------- // To display in right column -- // ---------------------- if (!@mysqli_select_db($dblink, $dbname)) { $rightbox .= "<h3><strong class='red'>ERROR</strong> - " . "Could not connect to database "" . $dbname . "" " . "on server "localhost"</h3>\r\n"; // } elseif (empty($SQL)) { } elseif (!file_exists(sql_source_file_name($query, $cmdtype))) { $rightbox .= "<p><strong class='red'>ERROR</strong> - " . "<strong>Found no definitions of tables to " . $cmdtype . "</strong> " . "for application "" . $dbapp . "" " . "in database "" . $dbname . "" " . "on server "" . $dbhost . "" " . "</p>\r\n"; } elseif ($dblock) { $rightbox .= "<h3><strong class='red'>ERROR</strong> - " . "Database "" . $dbname . "" " . "on server "" . $dbhost . "" " . "is not under control of the current user</h3>\r\n"; } else { // ---------------------- // Display results // ---------------------- $rightbox .= "<h3>Now trying to " . $cmdtype . " tables " . "for application "" . $dbapp . "" " . "in database "" . $dbname . "" " . "on server "" . $dbhost . "" " . "</h3>\r\n"; $rightbox .= "<p><strong class='green'>SUCCESS</strong> - " . "User <strong>'" . $mysql_admin_user . "'@'" . $dbhost . "'</strong> " . "connected to host <strong>'" . $dbhost . "'</strong></p>"; $num = check_tables($dbhost, $dbuser, $dbpass, $dbname, $dblock); if (!isset($_REQUEST["doit"])) { if ($num > 0) { $rightbox .= "<p><strong class='red'>WARNING</strong> - " . "<strong>" . $num . " tables already exist " . "in database '" . $dbname . "' on '" . $dbhost . "'</strong>. " . "<br><strong class='red'>Do you really want to delete " . "and then recreate these tables?</strong></p>"; } else { $rightbox .= "<p><strong class='red'>WARNING</strong> - " . "<strong class='red'>Do you really want to " . $cmdtype . " tables " . "in database '" . $dbname . "' on '" . $dbhost . "'?</strong></p>";
function parse_and_execute_sql_source_file($dblink, $dbfullapp, $cmdtype) { if (!file_exists($dbfile = sql_source_file_name($dbfullapp, $cmdtype))) { return false; } $dbtables = array(); $handle = @fopen($dbfile, "r"); if ($handle) { while (($sqlStmt = fgets($handle)) !== false) { $sqlStmt = trim($sqlStmt); if (!empty($sqlStmt) && !preg_match("/--.*/i", $sqlStmt)) { $result = @mysqli_query($dblink, $sqlStmt); flush(); // important if (preg_match("/^CREATE TABLE IF NOT EXISTS `?([^( `]*)`?/", $sqlStmt, $res)) { $dbtables[$res[1]] = (bool) $result ? "" : mysqli_error($dblink); } elseif (preg_match("/^INSERT INTO `?([^( `]*)`?/", $sqlStmt, $res)) { $dbtables[$res[1]] = (bool) $result ? "" : mysqli_error($dblink); } } } // end while //if (!feof($handle)) {echo "Error: unexpected fgets() fail\n";} fclose($handle); } return $dbtables; }