Guest User

Untitled

a guest
Feb 8th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <?php
  2.  
  3. $host='127.0.0.1';
  4. $db = 'mi_base_datos';
  5. $username = 'postgres';
  6. $password = '1706';
  7.  
  8. ?>
  9.  
  10. <?php
  11. require_once 'dbconfig_postgres.php';
  12. $dsn = "pgsql:host=$host;port=5432;dbname=$db;user=$username;password=$password";
  13.  
  14. try{
  15. $base_postgres = new PDO($dsn);
  16. $base_postgres->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  17. //echo "<div class='conectado_bd bg_verde'><div>PostGres</div><div>ON</div></div></div>";
  18.  
  19. }catch (PDOException $e){
  20. echo "BD fuera de servicio";
  21. }
  22. ?>
  23.  
  24. $registros=$base_postgres->prepare('Select id,nombre,correo From "mi_esquema"."mi_tabla"');
  25.  
  26. $registros->execute(array());
  27. //Por si quieres saber cuantos registros arrojo la consulta
  28. $total_registros = $registros_niscap->rowCount();
  29.  
  30. $registros = $registros->fetchAll( PDO::FETCH_OBJ );
Add Comment
Please, Sign In to add comment