Guest User

dbconfig

a guest
Oct 26th, 2016
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. <?php
  2. $db = isset($_POST['db']) ? $_POST['db'] : '';
  3. class Database
  4. {
  5.  
  6. private $host = "localhost";
  7. private $db_name = "designer6";
  8. private $username = "root";
  9. private $password = "123456";
  10. public $conn;
  11.  
  12. public function dbConnection()
  13.  
  14. {
  15. $db = isset($_POST['db']) ? $_POST['db'] : '';
  16. $this->conn = null;
  17. try
  18. {
  19.  
  20. $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
  21. $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  22. }
  23. catch(PDOException $exception)
  24. {
  25. echo "Connection error: " . $exception->getMessage();
  26. }
  27.  
  28. return $this->conn;
  29. }
  30. }
  31. ?>
Add Comment
Please, Sign In to add comment