-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
40 lines (33 loc) · 1.19 KB
/
install.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
33
34
35
36
37
38
39
40
<?php
// Include the database connection.
require_once 'database_connection.php';
// Drop the 'users' table (if it exists).
$mysqli->query("DROP TABLE IF EXISTS `users`;");
// Create the 'users' table.
$sql = "CREATE TABLE `users` (
`id` INT NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL COMMENT 'The username of the user.',
`password` varchar(255) NOT NULL COMMENT 'The password of the user.',
`name` varchar(255) NULL DEFAULT '' COMMENT 'The name of the user.',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Storage for user authentication details.';";
$mysqli->query($sql);
// Generate two test users.
$userData = [
[
'user1',
password_hash('password', PASSWORD_DEFAULT),
'User One',
],
[
'user2',
password_hash('letmein', PASSWORD_DEFAULT),
'User Two',
],
];
$stmt = $mysqli->prepare("INSERT INTO `users`(`username`, `password`, `name`) VALUES (?, ?, ?);");
foreach ($userData as $id => $userDatum) {
$stmt->bind_param("sss", ...$userDatum);
$stmt->execute();
}
echo 'Authentication example table (re)created and the default users installed.' . PHP_EOL;