-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_table.php
44 lines (36 loc) · 1.16 KB
/
create_table.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
<?php
$host = 'localhost'; // Change to your database server host
$username = 'your_username'; // Change to your database username
$password = 'your_password'; // Change to your database password
$database = 'your_database'; // Change to your database name
// Create a connection to the database
$conn = new mysqli($host, $username, $password);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Select the database
$sql = "CREATE DATABASE IF NOT EXISTS $database";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully.<br>";
} else {
echo "Error creating database: " . $conn->error;
}
// Connect to the specific database
$conn = new mysqli($host, $username, $password, $database);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create the table
$sql = "CREATE TABLE url_shortener (
id INT AUTO_INCREMENT PRIMARY KEY,
original_url VARCHAR(255) NOT NULL
)";
if ($conn->query($sql) === TRUE) {
echo "Table created successfully.";
} else {
echo "Error creating table: " . $conn->error;
}
$conn->close();
?>