<?php error_reporting ( 1 ); // error ditampilkan class Database { private $host = "" ; private $dbname = "" ; private $user = "root" ; private $password = "" ; private $port = "3306" ; private $conn ; // function yang pertama kali di-load saat class dipanggil public function __construct () { // koneksi database try { $this -> conn = new PDO ( "mysql:host= $this -> host ;port= $this -> port ;dbname= $this -> dbname ;charset=utf8" , $this -> user , $this -> password ); } catch ( PDOException $e ) { echo "Koneksi gagal" ; } } public function tampil_data ( $id_barang ){ $query = $this -> conn -> prepare ( " SELECT * FROM WHERE = ? " ); $query -> execute ( array ( $id_barang )); // mengambil satu data dengan fetch