Advertisement
Guest User

Untitled

a guest
Jun 17th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1. <?php
  2.  
  3.     class Database {
  4.  
  5.         public function __construct() {
  6.  
  7.             /*** hostname ***/
  8.             $hostname = $config['db']['host'];
  9.             /*** dbname ***/
  10.             $dbname = $config['db']['dbname'];
  11.             /*** username ***/
  12.             $username = $config['db']['username'];
  13.             /*** password ***/
  14.             $password = $config['db']['password'];
  15.  
  16.             function dbcon ($hostname, $username, $password){
  17.                 $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
  18.                 $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  19.  
  20.             }
  21.  
  22.             try {
  23.                 $dbh = dbcon ($hostname, $username, $password);
  24.                 print 'je hebt connectie';
  25.             } catch(PDOException $e) {
  26.                 echo $e->getMessage();
  27.             }
  28.  
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement