Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Contoh Penggunaan PDO MySQL
- * @author Pusat Ilmu Secara Detil
- * @version 1.0
- */
- try {
- // setup koneksi
- $dbh = new PDO("mysql:host=localhost;dbname=mahasiswa", "root", "",array(
- PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- echo 'Gagal Koneksi.Pastikan string koneksi sesuai<br/>';
- }
- /*** Query Select ***/
- $sql = $dbh->prepare("SELECT * FROM mhs");
- $sql->execute();
- while($mhs = $sql->fetch())
- {
- print $mhs['nim'] .' - '. $mhs['nama'] .' - '.$mhs['alamat']. '<br />';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement