Advertisement
Guest User

Untitled

a guest
Oct 29th, 2017
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $result0 = pg_query($db,
  2. "INSERT into dcd (dcd_id, name, key, notes)
  3. VALUES (0, 'esp8266-0', '0000', 'test ESP8266 DCD prototype')") or die('Data insert error: ' . pg_last_error());
  4.  
  5. $result0 = pg_query($db,
  6. "INSERT into dcd (dcd_id, name, key, notes)
  7. VALUES (1, 'one more dcd', 'passwd', 'nonexistent DCD')") or die('Data insert error: ' . pg_last_error());
  8.  
  9.  
  10. <html>
  11. <head></head>
  12. <body>
  13. <a href="radiation_db_status.php">db status</a><br/>
  14. <?php
  15.  
  16. function pg_connection_string() {
  17. return "dbname=d7ksk16elgce9a host=ec2-54-228-235-185.eu-west-1.compute.amazonaws.com port=5432 user=kbzwrksehfbdtl password=70f8d9d17c40d567f3d63a53945ccf02e90f26b17cdfae48ea744cfd8f521974 sslmode=require";
  18. }
  19. # Установка соединения с базой данных
  20. $db = pg_connect(pg_connection_string());
  21. if (!$db) {
  22. echo "Database connection error.\n";
  23. exit;
  24. } else echo "Connection ok<br>";
  25.  
  26. echo "*********";
  27. echo "<br/>\n";
  28.  
  29.  
  30.  
  31. $result0 = pg_query($db,
  32. "CREATE TABLE dcd (
  33. dcd_id serial PRIMARY KEY,
  34. name text,
  35. key text,
  36. notes text
  37. )") or die('Table creation error: ' . pg_last_error());
  38. if ($result0) echo "Table 'dcd' creation ok<br>";
  39.  
  40. $result0 = pg_query($db,
  41. "CREATE TABLE measure (
  42. measure_id serial,
  43. background real,
  44. datetime timestamp,
  45. dcd_id int,
  46. PRIMARY KEY (measure_id),
  47. FOREIGN KEY (dcd_id) REFERENCES dcd (dcd_id)
  48. )") or die('Table creation error: ' . pg_last_error());
  49. if ($result0) echo "Table 'measure' creation ok<br>";
  50.  
  51. echo "*********";
  52. echo "<br/>\n";
  53.  
  54.  
  55.  
  56. #FOREIGN KEY (имя_столбца_которое_является_внешним_ключом) REFERENCES имя_таблицы_родителя (имя_столбца_родителя);
  57.  
  58.  
  59. pg_free_result($result0);
  60. pg_close($db);
  61. ?>
  62. </body>
  63. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement