Created
September 27, 2017 03:56
-
-
Save dosjota/9892d0efd794149cce6f60e44289c1a7 to your computer and use it in GitHub Desktop.
Conexion PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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