Advertisement
androidmaker155

ad

Oct 14th, 2014
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.58 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Contoh Penggunaan PDO MySQL
  4.  * @author Pusat Ilmu Secara Detil
  5.  * @version 1.0
  6.  */
  7.  
  8. try {
  9.     // setup koneksi
  10.    $dbh = new PDO("mysql:host=localhost;dbname=mahasiswa", "root", "",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.    
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement