diff _xampp/contrib/postgresql.php @ 0:b12c99b7c3f0

commit for previous development
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 19 Jan 2015 17:13:49 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/_xampp/contrib/postgresql.php	Mon Jan 19 17:13:49 2015 +0100
@@ -0,0 +1,45 @@
+<html>
+<head>
+<title>PHP und PostgreSQL</title>
+</head>
+<body>
+<h1>PHP und PostgreSQL</h1>
+<table border="1">
+<tr>
+    <th>Interpret</th>
+    <th>Titel</th>
+    <th>Jahr</th>
+</tr>
+<?php
+
+    $conn_string = "host=localhost port=5432 dbname=cdcol  
+                    user=oswald password=geheim";
+
+    $db_handle = pg_connect($conn_string);
+    if(!$db_handle)
+        die("Kann Datenbank nicht erreichen!");
+
+    $query = "SELECT * FROM cds";
+
+    $result = pg_exec($db_handle, $query);
+
+    if (!$result) 
+    {
+        echo pg_errormessage($db_handle);
+    }
+    else
+    {
+        for ($row = 0; $row < pg_numrows($result); $row++)
+        {
+            $values = pg_fetch_array($result, $row, PGSQL_ASSOC);
+            echo "<tr>";
+            echo "<td>".$values['interpret']."</td>";
+            echo "<td>".$values['titel']."</td>";
+            echo "<td>".$values['jahr']."</td>";
+            echo "</tr>";
+        }
+    }
+?>
+</table>
+</body>
+</html>