From 05972182a250d7767d5ef2a8a707e2f769983b94 Mon Sep 17 00:00:00 2001 From: ed <ed@brz9.dev> Date: Sat, 7 Jan 2023 20:02:27 +0100 Subject: [PATCH] pg test --- proj/paper/index.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 proj/paper/index.php diff --git a/proj/paper/index.php b/proj/paper/index.php new file mode 100644 index 0000000..ca67dcc --- /dev/null +++ b/proj/paper/index.php @@ -0,0 +1,35 @@ +<?php + +$host = 'localhost'; +$dbname = 'test'; +$user = 'edpg'; +$password = 'edpg'; + +// Connect to the database +$db = pg_connect("host=$host dbname=$dbname user=$user password=$password"); + +if (!$db) { + // connection failed + echo "Error: Unable to open database\n"; +} else { + // connection succeeded + echo "Opened database successfully\n"; +} + +// Execute a query +$result = pg_query($db, "SELECT * FROM testab"); + +if (!$result) { + // query failed + echo "Error: Query failed\n"; +} else { + // query succeeded, loop through the rows + while ($row = pg_fetch_row($result)) { + echo "Name: $row[0]\n"; + } +} + +// close the connection +pg_close($db); + +?> \ No newline at end of file