Skip to content

Conexión a Postgres desde PHP

Kevin Johnson edited this page Apr 3, 2020 · 1 revision

index.php

<?php
  $user = 'grupoXX';
  $password = 'grupoXX';
  $databaseName = 'grupoXX';
  $db = new PDO("pgsql:dbname=$databaseName;host=localhost;port=5432;user=$user;password=$password");

  $query_string = "SELECT * FROM tabla;";
  $query = $db -> prepare($query_string);
  $query -> execute();
  $result = $query -> fetchAll();
?>

<table>
  <tr>
    <th>ID</th>
    <th>Nombre</th>
    <th>Altura</th>
  </tr>
  
  <?php
    foreach ($result as $r) {
      echo "<tr><td>$r[0]</td><</tr>";
    }
  ?>
</table>