Advertisement
Guest User

Untitled

a guest
Jan 19th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. ``` php
  2. <?php
  3. class Conexion {
  4. function conectar() {
  5. $conn = pg_connect("user=usuario password=clave host=direccion_ip port=puerto dbname=nombre_db");
  6.  
  7. if (!$conn) {
  8. echo "Error, Problemas al conectar con el servidor";
  9. exit;
  10. }else{
  11. return $conn;
  12. }
  13. }
  14.  
  15. function consulta($sql=null){
  16. $resultado = pg_query(Conexion::conectar(),$sql);
  17. $fila = array();
  18. while($row = pg_fetch_assoc($resultado)) {
  19. $fila[] = $row;
  20. }
  21. return $fila;
  22. }
  23. }
  24.  
  25. $conexion = new Conexion();
  26. $conexion->conectar();
  27.  
  28. $respuesta = $conexion->consulta("SELECT * FROM tabla");
  29.  
  30. print_r($respuesta);
  31. ?>
  32. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement