$dofile = ""; // Parse the comamndline (starting) for commandparameters // 1. Parse the URL sent by client (not working, but could restart itself later version) // XXX Need to adapt get_parse to also read URL-like (should that be necessary) if (get_parse()) { // Do some Processing of commandline arguments. For init, the standard filename IS database.cfg // could also include the setting of debug on the client side if ($doinit) { $dbfile = $config_dir . "database.cfg"; if ($dofile != "") { $dbfile = $dofile; } $log->lwrite("main:: Option do_init selected, reading db file: " . $dofile, 1); $cfg = read_database($dbfile); // Load $cfg Object from File $ret = fill_database($cfg); // Fill the MySQL Database with $cfg object $ret = file_database($config_dir . "newdbms.cfg", $cfg); // Make backup to other file $ret = print_database($cfg); } if ($doreset) { $log->lwrite("main:: Option do_reset selected", 1); } $log->lwrite("Done processing command parameters at " . date("r") . "\n", 2); } else { $log->lwrite("main:: get_parse had no commandline parameters " . date("r") . "\n", 1); } // Start with loading the database into a local $config structure. This takes // time once , but once we are in the loop it will save us time every loop. $log->lwrite("main:: Loading the database");
function get_parse() { global $appmsg; global $apperr; global $action; global $icsmsg; global $config_dir; global $log_dir; foreach ($_GET as $ind => $val) { decho("get_parse:: index: {$ind} and val: {$val}<br>", 1); switch ($ind) { case "action": $action = $val; break; case "message": $icsmsg = json_decode($val); $apperr .= "\n ics: " . $icsmsg; break; // ******* URL COMMANDLINE OPTIONS BELOW *** // Initial or repair load of th edatabase for LamPI // Need to specify this option on the URL: http://<my-lampi-url>/frontend_set.php?load // // ******* URL COMMANDLINE OPTIONS BELOW *** // Initial or repair load of th edatabase for LamPI // Need to specify this option on the URL: http://<my-lampi-url>/frontend_set.php?load // case "load": echo "load:: config file: " . $config_dir . "database.cfg\n"; $cfg = read_database($config_dir . "database.cfg"); // Load $cfg Object from File echo " cfg read; "; print_database($cfg); echo " now filling mysql; "; $ret = fill_database($cfg); // Fill the MySQL Database with $cfg object echo " Making backup; "; $ret = file_database($config_dir . "newdbms.cfg", $cfg); // Make backup to other file echo " Backup newdbms.cfg made"; if ($val < 1) { decho("file_database:: value must be >0"); } exit(0); break; case "print": $cfg = load_database(); print_database($cfg); exit(0); break; case "store": $cfg = load_database(); // Fill $cfg from MySQL $ret = file_database($config_dir . "newdbms.cfg", $cfg); // Make backup to other file if ($val < 1) { decho("store:: value must be >0"); } echo "Backup is complete"; exit(0); break; } // Switch ind } // Foreach return 0; }
<?php //Start a connection to the database page_search, Truncate the tables and fill the database again. $conn = start_conn("page_search"); $conn->query("TRUNCATE TABLE page"); $conn->query("TRUNCATE TABLE word"); $conn->query("TRUNCATE TABLE occurrence"); fill_database(); $conn->close(); //Starts a database connection. function start_conn($s) { $user = '******'; $pass = ''; $db = $s; $conn = new mysqli('localhost', $user, $pass, $db); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } return $conn; } //Finds all files in the directory above engine.php and in all directories below it and adds them to the database. //Also opens these pages and take out all the words in them. Called from admin_search_database. function fill_database() { $conn = start_conn('page_search'); $content = ''; $Directory = new RecursiveDirectoryIterator("../"); $Iterator = new RecursiveIteratorIterator($Directory, RecursiveIteratorIterator::CHILD_FIRST); try { foreach ($Iterator as $fullFileName => $fileSPLObject) {