-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateTable.php
More file actions
28 lines (24 loc) · 830 Bytes
/
createTable.php
File metadata and controls
28 lines (24 loc) · 830 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
<html>
<?php
# This function reads your DATABASE_URL config var and returns a connection
# string suitable for pg_connect. Put this in your app.
function pg_connection_string_from_database_url() {
extract(parse_url($_ENV["DATABASE_URL"]));
return "user=$user password=$pass host=$host dbname=" . substr($path, 1); # <- you may want to add sslmode=require there too
}
# Here we establish the connection. Yes, that's all.
$db = pg_connect(pg_connection_string_from_database_url());
# main | id (int) | question name (text)
$main="CREATE TABLE MAIN (
ID INT PRIMARY KEY,
NAME TEXT);";
$result=pg_query($db,$main);
# users | ip address (text) | questions voted on (text)
$users="CREATE TABLE USERS (
IP TEXT PRIMARY KEY,
VOTED TEXT);";
$result=pg_query($db,$users);
echo pg_last_error();
pg_close($db);
?>
</html>