parent
5fe901253c
commit
b1da73b743
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
function get_database()
|
||||
{
|
||||
global $data_source_name;
|
||||
// The presence of the .guard file says that the database has already been initialized.
|
||||
$database_exists = file_exists(__DIR__ . "/.guard");
|
||||
$pdo = new PDO($data_source_name, DATABASE_USER, DATABASE_PASSWORD);
|
||||
|
||||
if ($database_exists) {
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
foreach (scandir(__DIR__) as $file) {
|
||||
if (preg_match("/.*\.sql$/i", $file)) {
|
||||
$content = file_get_contents(__DIR__ . "/" . $file);
|
||||
|
||||
foreach (preg_split("/;\s*/", $content) as $req) {
|
||||
if ($req === "")
|
||||
break;
|
||||
$pdo->query($req);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
touch(__DIR__ . "/.guard");
|
||||
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
|
||||
-- drop tables here
|
||||
DROP TABLE IF EXISTS FormEntries;
|
||||
|
||||
CREATE TABLE FormEntries(name varchar, description varchar);
|
||||
|
||||
|
||||
|
Loading…
Reference in new issue