database.php 698 B

1234567891011121314151617181920212223
  1. <?php
  2. class Database {
  3. private $host = '10.15.10.8';
  4. private $db_name = 'inventory_db';
  5. private $username = 'inventory_db';
  6. private $password = 'fNk@6P[!cTK)wgkO';
  7. public $conn;
  8. public function getConnection() {
  9. $this->conn = null;
  10. try {
  11. $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
  12. $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  13. $this->conn->exec("set names utf8");
  14. } catch(PDOException $exception) {
  15. echo "Connection error: " . $exception->getMessage();
  16. }
  17. return $this->conn;
  18. }
  19. }
  20. ?>