Skip to content

Instantly share code, notes, and snippets.

@dosjota
Created September 27, 2017 03:56
Show Gist options
  • Save dosjota/9892d0efd794149cce6f60e44289c1a7 to your computer and use it in GitHub Desktop.
Save dosjota/9892d0efd794149cce6f60e44289c1a7 to your computer and use it in GitHub Desktop.
Conexion PostgreSQL
<?php
$dbconn = pg_connect("host=localhost port=5432 dbname=nombreBaseDeDatos user=postgres password=xxxxxxx");
$estado = pg_connection_status($dbconn);
echo ($estado === PGSQL_CONNECTION_OK) ? 'Estado de la conexión ok' : 'No se ha podido conectar' ;
echo '<br>';
$resultado = pg_query($dbconn, "SELECT nombre FROM usuario");
$resultadoQuery = (!$resultado) ? "Ops! Imposible Ejecutar Query" : "Query Ok..." ;
echo $resultadoQuery;
echo '<br>';
while ($row = pg_fetch_row($resultado)) {
echo $row[0] . '<br>';
}
pg_query($dbconn, "UPDATE usuario SET nombre = 'usuario 5' where id = 5");
pg_query($dbconn, "INSERT INTO usuario(nombre) VALUES ('test')");
pg_query($dbconn, "DELETE FROM usuario where nombre='test'");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment