function isQuoted($offset, $text) { if ($offset > strlen($text)) { $offset = strlen($text); } $isQuoted = false; for ($i = 0; $i < $offset; $i++) { if ($text[$i] == "'") { $isQuoted = !$isQuoted; } if ($text[$i] == "\\" && $isQuoted) { $i++; } } return $isQuoted; } function query($sql) { global $mysqli; //echo '#<strong>SQL CODE TO RUN:</strong><br>' . htmlspecialchars($sql) . ';<br><br>'; if (!($query = $mysqli->query($sql))) { throw new Exception("Cannot execute request to the database {$sql}: " . $mysqli->error); } } set_time_limit(0); $mysqli = new mysqli(getenv('MYSQL_HOST'), getenv('MYSQL_USER'), getenv('MYSQL_PASSWORD'), '', getenv('MYSQL_PORT')); $mysqli->set_charset("utf8"); $sqlfile = $argv[1]; header('Content-Type: text/html;charset=utf-8'); sqlImport($sqlfile); echo "Peak MB: ", memory_get_peak_usage(true) / 1024 / 1024;
<?php include 'configuration.php'; include 'common.php'; if ($_GET['install']) { include 'model/schema.php'; set_time_limit(0); $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, 'mysql'); $mysqli->set_charset("utf8"); header('Content-Type: text/html;charset=utf-8'); try { echo 'Pinging ' . PROJECT_DB . ' Database ... <br />'; echo '<hr />'; if (!databaseExists(PROJECT_DB)) { echo PROJECT_DB . ' does not exist ...<br />'; echo 'Creating ' . PROJECT_DB . '... <br />'; sqlImport('install.sql'); echo PROJECT_DB . " created successfully.<br />"; } else { echo PROJECT_DB . ' already exists. <br />'; } } catch (Exception $e) { echo 'Exception caught: ' . $e->getMessage() . "<br />"; } } else { echo '<p><a href="index.php?install=1">Create ' . PROJECT_DB . '</a></p>'; } ?> <!-- /php --> </body>