-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_conf.php
41 lines (35 loc) · 1.05 KB
/
database_conf.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
<?php
// IN DEVELOPMENT MODE, USE THIS
// $env = parse_ini_file('.env');
// $servername = $env['DB_HOST'];
// $username = $env['DB_USER'];
// $password = $env['DB_PASS'];
// $dbname = $env['DB_NAME'];
// $port = $env['DB_PORT'];
// IN PRODUCTION MODE, USE THIS
$servername = getenv('DB_HOST');
$username = getenv('DB_USER');
$password = getenv('DB_PASS');
$dbname = getenv('DB_NAME');
$port = getenv('DB_PORT');
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, $port);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// SQL to create table
$sql = "CREATE TABLE IF NOT EXISTS posts (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
image VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
// Execute create table query
if ($conn->query($sql) === TRUE) {
// echo "Table created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
?>