-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateDB.php
More file actions
33 lines (23 loc) · 800 Bytes
/
Copy pathcreateDB.php
File metadata and controls
33 lines (23 loc) · 800 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
<?php
try {
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ergasiaDB";
$tableName = "formParticipants";
$db = new PDO("mysql:host=$servername", $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->query("CREATE DATABASE IF NOT EXISTS $dbname");
$db->query("use $dbname");
$sql = "CREATE TABLE IF NOT EXISTS $tableName (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
fullname VARCHAR(30) NOT NULL,
email VARCHAR(50),
website VARCHAR(50),
gender VARCHAR(10),
message VARCHAR(500),
reg_date TIMESTAMP)";
$db->exec($sql);
}catch(PDOException $e){ echo "Error: " . $e->getMessage(); }
$db = null;
?>