public function Close() { $this->log .= "\tCompleted: " . number_format(microtime(true) - $this->start, 4) . " seconds:\r\n"; singleLog($this->log, $this->path); }
/* * All this crap switches the environment to run from the testing database and session pool. * Pass in /reset, and the database and sessions will be cleared, and a default user will be created. * * Magic! */ $dbCredentials = 'UnitTestDBCredentials'; if (!file_exists(UNITTESTSESSIONPATH)) { mkdir(UNITTESTSESSIONPATH); } session_save_path(UNITTESTSESSIONPATH); if (isset($Path[0]) && $Path[0] == 'reset') { $rm = "rm " . UNITTESTSESSIONPATH . "*"; $rm = `{$rm}`; $db = new MySQLDatabase('UnitTestDBCredentials'); $tables = $db->Query("\n\t\tSELECT table_name AS `table`\n\t\tFROM information_schema.tables\n\t\tWHERE table_schema = " . $db->Quote($UnitTestDBCredentials['name']) . ";\n\t"); singleLog($tables); if ($tables) { $db->Query("SET FOREIGN_KEY_CHECKS = 0;"); while ($table = $tables->Fetch()) { singleLog($db->Query("DROP TABLE IF EXISTS " . $table['table'] . ";")); } $db->Query("SET FOREIGN_KEY_CHECKS = 1;"); } $dump = "mysqldump -u " . $DevDBCredentials['user'] . " -p" . $DevDBCredentials['pass'] . " -d " . $DevDBCredentials['name'] . " | mysql -u " . $UnitTestDBCredentials['user'] . " -p" . $UnitTestDBCredentials['pass'] . " -D" . $UnitTestDBCredentials['name'] . ""; $dump = `{$dump}`; $makeUser = $db->Query("INSERT INTO tblUsers (username, password, accountType, displayName, email) VALUES ('joe', 'nohomohug', 'Standard', 'Joe Testmoore', '*****@*****.**');"); APIResponse(RESPONSE_200, "Cleared the database and sessions."); exit; }
public function AddToDatabase() { $this->DB->Prepare("\n\t\t\tINSERT INTO tblIngredients\n\t\t\t\t(userID, type, title, description, baseIngredientID, createStamp, modifyStamp)\n\t\t\t\tVALUES\n\t\t\t\t(:userID, :type, :title, :description, :baseIngredientID, :createStamp, :modifyStamp)\n\t\t"); $id = $this->DB->Execute(array(":userID" => $this->Session->ID, ":type" => $this->Type, ":title" => $this->Title, ":description" => $this->Description, ":baseIngredientID" => Nullable($this->BaseIngredientID()), ":createStamp" => $this->CreateStamp, ":modifyStamp" => microtime(true))); if ($id) { $this->ID = $id; } singleLog("Created ingredient #{$id}"); return $id; }
public static function GC() { if (MYSQLVAREXPIREDAYS && file_exists(MYSQLVARPATH)) { $expireTime = time() - MYSQLVAREXPIREDAYS * 86400; foreach (scandir(MYSQLVARPATH) as $sessionFolder) { if (stristr($sessionFolder, 'sqldb-') && filemtime(MYSQLVARPATH . $sessionFolder) < $expireTime) { $delete = "rm -r " . MYSQLVARPATH . $sessionFolder; $delete = `{$delete}`; singleLog("MySQLDatabase Garbage Collection for {$sessionFolder}"); } } } }