Advertisement
Guest User

Testing postgres fetch_array

a guest
Nov 11th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2.  
  3. $gaSql['user'] = "postgres";
  4. $gaSql['password'] = "password";
  5. $gaSql['db'] = "pg_testing";
  6. $gaSql['server'] = "localhost";
  7.  
  8. $gaSql['link'] = pg_connect(
  9.      "host=".$gaSql['server'].
  10.      " dbname=".$gaSql['db'].
  11.      " user=".$gaSql['user'].
  12.      " password=".$gaSql['password']
  13. ) or die('Could not connect:' . pg_last_error());
  14.  
  15. $sQuery = "SELECT * FROM users";
  16.  
  17. $rResult = pg_query($gaSql['link'], $sQuery) or die(pg_last_error());
  18.  
  19. $iTotal = pg_num_rows($rResult);
  20.  
  21. echo $iTotal;
  22.  
  23. output> 4
  24.  
  25. while ($aRow = pg_fetch_array($rResult, null, PGSQL_ASSOC)) {
  26.     print_r($aRow);
  27. }
  28.  
  29. output>
  30. Array
  31. (
  32.     [id] => 1
  33.     [name] => John
  34. )
  35. Array
  36. (
  37.     [id] => 2
  38.     [name] => Smyth
  39. )
  40. Array
  41. (
  42.     [id] => 3
  43.     [name] => Arthur
  44. )
  45. Array
  46. (
  47.     [id] => 4
  48.     [name] => George
  49. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement