-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.php
More file actions
53 lines (46 loc) · 1.38 KB
/
install.php
File metadata and controls
53 lines (46 loc) · 1.38 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
require_once(dirname(__FILE__) . '\config.php');
function install($user, $pass) {
$dbh = new PDO("mysql:host=localhost",$user,$pass);
$filehandle = fopen(SITE_ROOT . '\SQL\init.sql', 'r') or die("Unable to open init.sql.");
$init_sql = fread($filehandle, filesize(SITE_ROOT . '\SQL\init.sql'));
fclose($filehandle);
$filehandle = fopen(SITE_ROOT . '\SQL\populate.sql', 'r') or die("Unable to open populate.sql.");
$populate_sql = fread($filehandle, filesize(SITE_ROOT . '\SQL\populate.sql'));
fclose($filehandle);
$dbh->exec($init_sql);
$dbh->exec($populate_sql);
return true;
}
$message = "";
if( isset($_POST) && !empty($_POST['username']) && isset($_POST['password']) ) {
try {
if( install($_POST['username'], $_POST['password']) ) {
$message = "Success!";
}
}
catch( Exception $e ) {
$message = "ERROR: " . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Install</title>
</head>
<body>
<?php if( $message === "" ) : ?>
<p>Please enter the root or admin username and password for MySQL to add the TA Scheduler database and user.</p>
<form action="#" method="POST">
<label>Username</label>
<input id="username" type="text" name="username" />
<label>Password</label>
<input id="password" type="password" name="password" />
<input type="submit" value="Submit" />
</form>
<?php else : ?>
<p><?php echo $message; ?></p>
<?php endif; ?>
</body>
</html>