-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_createtables.php
50 lines (37 loc) · 1.5 KB
/
admin_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
47
48
49
50
<?php
/* PURPOSE:
Utilities for creating Table table.
Should store Item, which is a composite object (arrays of Identiers, Names...) be a replacement of arrays; hopefully
*/
$servername = "localhost:3308";// This had to be set to:3308 on this Win 10 WAMP install
$username = "homeinventorydev";
$password = "xFog2f8NIrP6MGpl";
$dbname = "homeinventorydevdb";
// $conn = "";
echo "Table Item and Cardboard creation script<br>";
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 "<br>Table Item created successfully";
$sql = "CREATE TABLE Cardboard (jdoc JSON)";
// use exec() because no results are returned
$conn->exec($sql);
echo "<br>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();
}
else{
echo $sql ."<br> Error Message: " . $e->getMessage();
}
}
$conn = null;
?>