Advertisement
androidmaker155

sdf

Oct 14th, 2014
3,465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Contoh Penggunaan PDO PGSQL
  4.  * @author Pusat Ilmu Secara Detil
  5.  * @version 1.0
  6.  */
  7.  
  8. try {
  9.     // setup koneksi
  10.    $dbh = new PDO("pgsql:host=localhost;dbname=mahasiswa", "root", "root",5432,array(
  11.               PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));  
  12. }
  13. catch(PDOException $e)
  14. {
  15.     echo $e->getMessage();
  16.     echo 'Gagal Koneksi.Pastikan string koneksi sesuai<br/>';
  17. }
  18.  
  19. /*** Query Select ***/
  20. $sql = $dbh->prepare("SELECT * FROM mhs");
  21. $sql->execute();
  22. while($mhs = $sql->fetch())
  23. {
  24.     print $mhs['nim'] .' - '. $mhs['nama'] .' - '.$mhs['alamat']. '<br />';
  25. }
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement