Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $result0 = pg_query($db,
- "INSERT into dcd (dcd_id, name, key, notes)
- VALUES (0, 'esp8266-0', '0000', 'test ESP8266 DCD prototype')") or die('Data insert error: ' . pg_last_error());
- $result0 = pg_query($db,
- "INSERT into dcd (dcd_id, name, key, notes)
- VALUES (1, 'one more dcd', 'passwd', 'nonexistent DCD')") or die('Data insert error: ' . pg_last_error());
- <html>
- <head></head>
- <body>
- <a href="radiation_db_status.php">db status</a><br/>
- <?php
- function pg_connection_string() {
- return "dbname=d7ksk16elgce9a host=ec2-54-228-235-185.eu-west-1.compute.amazonaws.com port=5432 user=kbzwrksehfbdtl password=70f8d9d17c40d567f3d63a53945ccf02e90f26b17cdfae48ea744cfd8f521974 sslmode=require";
- }
- # Установка соединения с базой данных
- $db = pg_connect(pg_connection_string());
- if (!$db) {
- echo "Database connection error.\n";
- exit;
- } else echo "Connection ok<br>";
- echo "*********";
- echo "<br/>\n";
- $result0 = pg_query($db,
- "CREATE TABLE dcd (
- dcd_id serial PRIMARY KEY,
- name text,
- key text,
- notes text
- )") or die('Table creation error: ' . pg_last_error());
- if ($result0) echo "Table 'dcd' creation ok<br>";
- $result0 = pg_query($db,
- "CREATE TABLE measure (
- measure_id serial,
- background real,
- datetime timestamp,
- dcd_id int,
- PRIMARY KEY (measure_id),
- FOREIGN KEY (dcd_id) REFERENCES dcd (dcd_id)
- )") or die('Table creation error: ' . pg_last_error());
- if ($result0) echo "Table 'measure' creation ok<br>";
- echo "*********";
- echo "<br/>\n";
- #FOREIGN KEY (имя_столбца_которое_является_внешним_ключом) REFERENCES имя_таблицы_родителя (имя_столбца_родителя);
- pg_free_result($result0);
- pg_close($db);
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement