-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_config.php
49 lines (36 loc) · 962 Bytes
/
db_config.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
41
42
43
44
45
46
47
48
49
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "notes_app";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_errno) {
echo "Database connection failed!<br>";
echo "Reason: " . $conn->connect_error;
exit();
}
$sql = "CREATE DATABASE IF NOT EXISTS $dbname";
$qry = $conn->query($sql);
if ($qry) {
echo "Database created successfully.";
} else {
echo "Database has not been created!!<br>";
echo "Reason: " . $conn->error;
exit();
}
$conn->select_db($dbname);
$sql = "CREATE TABLE IF NOT EXISTS users (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
password VARCHAR(16) NOT NULL,
email VARCHAR(100) NOT NULL
)";
$qry = $conn->query($sql);
if ($qry) {
echo "<br/>Table 'users' created successfully.";
} else {
echo "Table 'users' has not been created!!<br>";
echo "Reason: " . $conn->error;
exit();
}
?>