<?php include_once "/var/www-croma/database/config.php"; include_once "/var/www-croma/database/allTables.php"; function dropTables() { $con = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error() . "\n"; return; } $sql = "USE " . DB_DATABASE; if (!mysqli_query($con, $sql)) { echo "Error selecting datbase" . DB_DATABASE . mysqli_error($con); return; } $tables = array("profiles", "teams", "usersVsTeams", "emailsVsUsers", "outreach", "media", "hourCounting", "timesVsOutreach", "usersVsOutreach", "notifications", "permissions", "roles", "usersVsRoles", "permissionsVsRoles", "oldHoursVsTeams"); foreach ($tables as $table) { $sql = "DROP TABLE {$table};"; if (!mysqli_query($con, $sql)) { echo "Error dropping {$table}: " . mysqli_error($con) . "\n"; return; } } } dropTables();
$testConfig = ['connection' => parse_ini_file(OMEKA_PATH . '/application/test/config/database.ini')]; $application = Omeka\Mvc\Application::init(array_merge($config, $testConfig)); $entityManager = $application->getServiceManager()->get('Omeka\\EntityManager'); // Create new tables. dropTables($entityManager->getConnection()); $schemaTool = new Doctrine\ORM\Tools\SchemaTool($entityManager); $schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata()); // Build the schema SQL. $user = escapeshellarg($testConfig['connection']['user']); $password = escapeshellarg($testConfig['connection']['password']); $dbname = escapeshellarg($testConfig['connection']['dbname']); $schemaSql = 'SET FOREIGN_KEY_CHECKS = 0;' . PHP_EOL; $schemaSql .= shell_exec("mysqldump --compact --user {$user} --password={$password} {$dbname}"); $schemaSql .= 'SET FOREIGN_KEY_CHECKS = 1;' . PHP_EOL; $schemaSql = preg_replace('/\\/\\*.+\\*\\/;\\n/', '', $schemaSql); file_put_contents('data/install/schema.sql', $schemaSql); // Clean up. dropTables($entityManager->getConnection()); /** * Drop all existing tables, even those not defined in the schema. * * @param Doctrine\DBAL\Connection $connection */ function dropTables(Doctrine\DBAL\Connection $connection) { $connection->query('SET FOREIGN_KEY_CHECKS=0'); foreach ($connection->getSchemaManager()->listTableNames() as $table) { $connection->getSchemaManager()->dropTable($table); } $connection->query('SET FOREIGN_KEY_CHECKS=1'); }
/** * displayStepThree * * @return void */ function displayStepThree() { // Check required fields $requiredFields = array('dbhost', 'dbname', 'dbuser', 'dbpass'); $missingRequired = false; foreach ($requiredFields as $field) { if (!isset($_POST[$field])) { $missingRequired = true; } } if ($missingRequired) { echo ' <script type="text/javascript"> $(document).ready(function() { $(\'#dbhost\').focus(); }); </script>'; displayStepTwo("<p class=\"error\">" . T_('You forgot a required field. Please fill out all required fields.') . "</p>"); return; } $connection = @mysql_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpass']); if (!$connection) { displayStepTwo("<p class=\"error\">" . T_('Could not connect to the database. Please try again.') . "</p>"); return; } mysql_select_db($_POST['dbname']) or die("<h1>Error</h1><p><b>Connection made, but database could not be found!</b></p>" . mysql_error()); $file = fopen('inc/config_inc.php', 'w') or die("<h1>Error Creating Config File</h1>"); $str = "<?php \$cfg_mysql_host = '" . $_POST['dbhost'] . "'; \$cfg_mysql_db = '" . $_POST['dbname'] . "'; \$cfg_mysql_user = '******'dbuser'] . "'; \$cfg_mysql_pass = '******'dbpass'] . "'; ?" . ">"; fwrite($file, $str) or die("<h1>Could not write to config.</h1>"); fclose($file); include_once 'inc/install_inc.php'; echo ' <div id="column"> <h1>' . T_('Install') . 'Family Connections</h1> <form class="nofields" action="install.php" method="post"> <h2>' . T_('Checking Database Connection') . '</h2> <p style="text-align:center">' . T_('Step 3 of 5') . '</p> <div class="progress"><div style="width:60%"></div></div>'; dropTables(); echo ' <h3>' . T_('Awesome!') . '</h3> <div>' . T_('A connection was successfully made to the database. Please proceed to the next step.') . '</div> <p style="text-align:right;"><input id="submit" name="submit3" type="submit" value="' . T_('Next') . ' >>"/></p> <div class="clear"></div> </form> </div><!-- /column -->'; }
} $where = "AND phone_call = 1"; $dbh->exec(str_replace('%where%', $where, $sql), 'calls', $day); if ($display) { echo " OK\n"; } ################################################################### if ($display) { echo "Count stat for {$day}: "; } $arr = iteratorToArray($dbh->query("SELECT COUNT(*) as count FROM rm_tmp_ticket_stat")); if ($display) { echo $arr[0]['count'] . "\n"; } // переместить данные в основную таблицу if ($display) { echo "Move data to main table"; } $dbh->exec("DELETE FROM {$main_table} WHERE day = ?", $day); $dbh->exec("INSERT INTO {$main_table} (day, user_id, city_id, data_type, data) SELECT day, user_id, city_id, data_type, data FROM rm_tmp_ticket_stat WHERE day = ?", $day); if ($display) { echo " OK\n"; } if ($display) { echo "\n"; } } dropTables($display, $dbh); $obList->updated(); $end = microtime(true); M('Trace')->trace('report_ticket_stat', "Statistics for the last {$period} days has been counted up for " . round($end - $begin, 2) . " sec");
function tearDown() { parent::tearDown(); dropTables(); }
$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die('Could not connect to the database; ' . mysql_error()); if (isset($_GET['action'])) { echo 'Processing action: ' . $_GET['action']; echo '</br>'; switch ($_GET['action']) { case 'create': createDB(SQL_DB, $conn); break; case 'delete': deleteDB(SQL_DB, $conn); break; case 'tables': createTables(SQL_DB, $conn); break; case 'drop': dropTables(SQL_DB, $conn); break; case 'data': insertTestDataSet(SQL_DB, $conn); break; } } function createDB($dbName, $conn) { $sql = <<<EOS CREATE DATABASE todo_db EOS; $result = mysql_query($sql, $conn) or die('Could not create database:' . mysql_error()); } function deleteDB($dbName, $conn) {
$madPdo = new madPDOFramework('mysql:dbname=mad;host=localhost', 'root'); $madPdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); dropTables($madPdo); $vanillaPdo = new PDO('mysql:dbname=vanilla;host=localhost', 'root'); $vanillaPdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); dropTables($vanillaPdo); $tests = glob(dirname(__FILE__) . '/fixtures/*'); echo "Will run insert.sql {$insertIterations} times\n"; echo "Will run select tests {$testIterations} times\n"; foreach ($tests as $test) { $testName = substr($test, strrpos($test, DIRECTORY_SEPARATOR)); $madPdo->cacheReset(); truncateTables($madPdo); truncateTables($vanillaPdo); runSqlFile("{$test}/insert.sql", $madPdo); dropTables($vanillaPdo); $schema = exportSchema($madPdo); $schemaFile = "{$test}/schema.sql"; assertSqlFile($schemaFile, $schema); runSqlFile($schemaFile, $vanillaPdo); $data = exportData($madPdo); $dataFile = "{$test}/data.sql"; assertSqlFile($dataFile, $data); for ($i = 1; $i <= $insertIterations; $i++) { runSqlFile("{$test}/insert.sql", $vanillaPdo); } if ($insertIterations > 1) { for ($i = 1; $i <= $insertIterations - 1; $i++) { runSqlFile("{$test}/insert.sql", $madPdo); } }
$db->query('alter table Events add primary key(id)'); $db->query('alter table Persons add primary key(id)'); $db->query('alter table Countries add primary key(iso2)'); $db->query('alter table Competitions add primary key(id)'); echo "Setup primary keys.<br>"; } function generateResults($db) { // Setup AllResults table for use with generating statistics $db->query('drop table if exists AllResults'); $db->query('create view ResultsView as select competitionId,eventId,personId,best,average,countryId,gender from Results join Persons on Results.personId=Persons.id'); $db->query('create view ResultsViewCountries as select competitionId,eventId,personId,best,average,countryId, Countries.iso2 as countryCode,gender from ResultsView join Countries on ResultsView.countryId=Countries.id'); $db->query('create table AllResults (competitionId varchar(32), eventId varchar(6), personId varchar(10), best int(11), average int(11), countryId varchar(50), countryCode char(2), gender char(1), year smallint(5) unsigned)'); $db->query('insert into AllResults select competitionId,eventId,personId,best,average,countryId,countryCode,gender,year from ResultsViewCountries join Competitions on ResultsViewCountries.competitionId=Competitions.id'); $db->query('drop view ResultsViewCountries'); $db->query('drop view ResultsView'); echo "Setup AllResults table.<br>"; } $db = getDb(); stripTables($db); dropTables($db); setupPrimaryKeys($db); generateResults($db); echo "Import script finished.<br>"; $db->close();
Zend_Session::start(); $logger = Zend_Log::factory(array(array('writerName' => 'Stream', 'writerParams' => array('stream' => LOGS_PATH . '/testing.log'), 'filterName' => 'Priority', 'filterParams' => array('priority' => Zend_Log::DEBUG)))); Zend_Registry::set('logger', $logger); // get the config properties $configGlobal = new Zend_Config_Ini(APPLICATION_CONFIG, 'global', true); $configGlobal->environment = 'testing'; Zend_Registry::set('configGlobal', $configGlobal); $config = new Zend_Config_Ini(APPLICATION_CONFIG, 'testing'); Zend_Registry::set('config', $config); // get database type // for now only supporting MySQL, PostgreSQL, and SQLite // get the database type from the existing config files $testConfigDir = BASE_PATH . '/tests/configs/'; $dbTypes = getSqlDbTypes($testConfigDir); foreach ($dbTypes as $dbType) { try { echo 'Dropping and installing tables for database type: ' . $dbType . PHP_EOL; $dbAdapter = loadDbAdapter($testConfigDir, $dbType); dropTables($dbAdapter, $dbType); require_once BASE_PATH . '/core/controllers/components/UtilityComponent.php'; $utilityComponent = new UtilityComponent(); installCore($dbAdapter, $dbType, $utilityComponent); createDefaultAssetstore(); installModules($utilityComponent); releaseLock($dbType); } catch (Zend_Exception $ze) { echo $ze->getMessage(); exit(1); } } exit(0);
<?php session_start(); require_once "drop_tables.php"; //include("managing_HTML.php"); require_once "managing_base.php"; require_once "managing_files.php"; require_once "managing_session.php"; if (!isset($_GET['user'])) { showPage("delete_user_form"); } else { $user = $_GET['user']; $result = doInDatabase("SELECT IDu FROM USERS WHERE NICKNAME = \"{$user}\""); $resultk = mysql_fetch_assoc($result); $id = $resultk["IDu"]; echo "IDu: {$id} </br>"; if ($id) { dropTables($id); deleteDir("users/{$id}"); doInDatabase("DELETE FROM USERS WHERE NICKNAME = \"{$user}\""); echo "Usunięto użytkownika: {$user}, ID: {$id} </br>"; } destroySession(); }