-
Notifications
You must be signed in to change notification settings - Fork 0
/
createtables.php
46 lines (34 loc) · 1.32 KB
/
createtables.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
<?php
/* PURPOSE:
Utilities for creating Table table.
Ch
Should store Item, which is a composite object (arrays of Identiers, Names...) be a replacement of arrays; hopefully
*/
$servername = "localhost";
$username = "homeinventorydev";
$password = "855265600PLk";
$dbname = "homeinventorydevdb";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// sql to create JSON table
$sql = "CREATE TABLE Item (jdoc JSON)";
// use exec() because no results are returned
$conn->exec($sql);
echo "Table Item created successfully";
$sql = "CREATE TABLE Cardboard (jdoc JSON)";
// use exec() because no results are returned
$conn->exec($sql);
echo "Table Cardboard created successfully";
}
catch(PDOException $e)
{
//display a user friendly message
//if code:2002, message = the connection to the database could not be done. Check the connection parameters, check if the database has been created.
if($e->getCode() == 2002){
echo $sql ."<br> Code: " . $e->getCode() . "<br>The connection to the database could not be done. Check the connection parameters with your database admin." . $e->getMessage();
}
}
$conn = null;
?>