generated from WildCodeSchool/simple-mvc-old-caprover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigration.php
32 lines (27 loc) · 764 Bytes
/
migration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require 'vendor/autoload.php';
if (file_exists('config/db.php')) {
require 'config/db.php';
} else {
require 'config/db.php.dist';
}
require 'config/config.php';
try {
$pdo = new PDO(
'mysql:host=' . DB_HOST . '; charset=utf8',
DB_USER,
DB_PASSWORD
);
$pdo->exec('DROP DATABASE IF EXISTS ' . DB_NAME);
$pdo->exec('CREATE DATABASE ' . DB_NAME);
$pdo->exec('USE ' . DB_NAME);
if (is_file(DB_DUMP_PATH) && is_readable(DB_DUMP_PATH)) {
$sql = file_get_contents(DB_DUMP_PATH);
$statement = $pdo->prepare($sql);
$statement->execute();
} else {
echo DB_DUMP_PATH . ' file does not exist';
}
} catch (PDOException $exception) {
echo $exception->getMessage();
}