-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.inc.php
38 lines (30 loc) · 873 Bytes
/
db.inc.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
<?php
//fill these in
$host = "";
$root = "";
$password = "";//
$db = "";
//creates database and table if it doesnt already exist
try
{
$create = new PDO('mysql:host=localhost', $root, $password);
$create->exec("CREATE DATABASE IF NOT EXISTS rps;");
$create->exec("CREATE TABLE IF NOT EXISTS rps.rpsentries(
id INT(11) AUTO_INCREMENT PRIMARY KEY,
playerSelection INT(11) NOT NULL,
cpuSelection INT(11) NOT NULL,
winner INT(11) NOT NULL,
sessionTurn INT(11) NOT NULL,
session_id VARCHAR(40) NOT NULL,
sessionNum INT(11) NOT NULL);");
$pdo = new PDO('mysql:host=localhost;dbname='. $db, $root, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
}
catch(PDOException $e)
{
$error = 'Unable to connect to database server.';
include 'error.html.php';
exit();
}
?>