-
Notifications
You must be signed in to change notification settings - Fork 1
/
php_test.php
33 lines (28 loc) · 1.37 KB
/
php_test.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
<?php
// Initialize connection variables.
$host = "psql-hope.postgres.database.azure.com";
$database = "hope";
$user = "usr@psql-hope";
$password = "pwd";
// Initialize connection object.
$connection = pg_connect("host=$host dbname=$database user=$user password=$password")
or die("Failed to create connection to database: ". pg_last_error(). "<br/>");
print "Successfully created connection to database.<br/>";
// Drop previous table of same name if one exists.
$query = "DROP TABLE IF EXISTS inventory;";
pg_query($connection, $query)
or die("Encountered an error when executing given sql statement: ". pg_last_error(). "<br/>");
print "Finished dropping table (if existed).<br/>";
// Create table.
$query = "CREATE TABLE inventory (id serial PRIMARY KEY, name VARCHAR(50), quantity INTEGER);";
pg_query($connection, $query)
or die("Encountered an error when executing given sql statement: ". pg_last_error(). "<br/>");
print "Finished creating table.<br/>";
// Insert some data into table.
$name = '\'banana\'';
$quantity = 150;
$query = "INSERT INTO inventory (name, quantity) VALUES ($1, $2);";
pg_query($connection, $query)
or die("Encountered an error when executing given sql statement: ". pg_last_error(). "<br/>");
// Closing connection
pg_close($connection);