Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. <?php
  2. namespace Settings;
  3. use \PDO;
  4.  
  5. class Koneksi{
  6.  
  7. private $dbhost = "localhost";
  8. private $username = "root";
  9. private $password = "";
  10. private $dbname = "ajaxcrud";
  11. protected $db;
  12.  
  13. public function __construct(){
  14. if (!$this->db) {
  15. try {
  16. $konek = new PDO("mysql:host=$this->dbhost;dbname=$this->dbname", $this->username, $this->password);
  17. $konek->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  18. } catch (PDOException $e) {
  19. echo "Koneksi Gagal " . $e->getMessage();
  20. }
  21. $this->db = $konek;
  22.  
  23. }
  24. }
  25.  
  26. }
  27.  
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement