-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase_create.php
More file actions
35 lines (32 loc) · 885 Bytes
/
database_create.php
File metadata and controls
35 lines (32 loc) · 885 Bytes
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
<?php
// Enlai Li 261068637
// db info
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db";
try {
$mysqli = new mysqli($servername, $username, $password);
if ($mysqli->connect_error) {
throw new Exception($mysqli->connect_error);
}
// create database
$mysqli->query("CREATE DATABASE IF NOT EXISTS $dbname");
// create table
$mysqli->select_db($dbname);
$mysqli->query("
CREATE TABLE IF NOT EXISTS user_content (
number int NOT NULL AUTO_INCREMENT,
id VARCHAR(255) NOT NULL UNIQUE,
content TEXT NOT NULL,
password BOOLEAN NOT NULL,
visits INT NOT NULL DEFAULT 0,
date DATE NOT NULL DEFAULT CURDATE(),
PRIMARY KEY (number)
);
");
} catch (Exception $e) {
echo $e->getMessage();
} finally {
$mysqli->close();
}