Guest User

Untitled

a guest
Aug 22nd, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>テスト</title>
  6. <meta name="viewport" content="width=device-width">
  7. <link rel="stylesheet" type="text/css" href="css/style.css">
  8. <script type="text/javascript" src="js/jquery.js"></script>
  9. <script type="text/javascript" src="js/script.js"></script>
  10. <script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
  11.  
  12. </head>
  13. <body>
  14.  
  15. <!-- DBのデータをPHPで処理 -->
  16. <?php
  17.  
  18. // PostgreSQLに接続
  19. $conn = pg_connect('host=localhost dbname=test user=jiptsinfra016 password=Infra0610');
  20.  
  21. if( $conn ) {
  22. var_dump("接続に成功しました");
  23. } else {
  24. var_dump("接続できませんでした");
  25. }
  26.  
  27. // SQL文を実行
  28. $result = pg_query('SELECT * FROM test_json');
  29.  
  30. // 全てのデータを配列で取得
  31. $data = pg_fetch_all($result);
  32.  
  33. // ひとつずつ取得
  34. //$data = pg_fetch_result($result, 0, 0);
  35.  
  36. //html上に取得したデータを表示
  37. //var_dump($data);
  38.  
  39. print "<table id="dblist" summary="PostgreSQLのデータベースの一覧">n";
  40. print "<caption>データベース一覧</caption>n";
  41.  
  42. //テーブルヘッダとしてフィールド(カラム)名を出力
  43. print "<tr>n";
  44. $flds = pg_num_fields($result);
  45. for($i=0; $i<$flds; $i++){
  46. $field = pg_field_name($result, $i);
  47. printf("<th abbr="%s">%s</th>n", $field, $field);
  48. }
  49. print "</tr>n";
  50.  
  51. //データの出力
  52. foreach($data as $rows){
  53. print "<tr>n";
  54. foreach($rows as $value){
  55. printf("<td>%s</td>n", $value);
  56. }
  57. print "</tr>n";
  58. }
  59. print "</table>n";
  60.  
  61.  
  62. // PostgreSQLを切断
  63. $close = pg_close($conn);
  64.  
  65.  
  66. echo <<<EOM
  67. <script>
  68. $(document).ready(function()
  69. {
  70. $("#dblist").tablesorter();
  71. }
  72. );
  73. </script>
  74. EOM;
  75. ?>
  76. <!-- DBのデータをPHPで処理 -->
  77.  
  78. </body>
  79. </html>
Add Comment
Please, Sign In to add comment