Created
July 5, 2021 04:21
-
-
Save wildroo/2ee19160ef9425d9ec186ba4a1585ca7 to your computer and use it in GitHub Desktop.
DB Config PHP File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DBClass { | |
private $host = "<your_host>"; | |
private $username = "<your_user_name>"; | |
private $password = "<your_passowrd>"; | |
private $database = "<your_db_name>"; | |
public $connection; | |
// get the database connection | |
public function getConnection(){ | |
$this->connection = null; | |
try{ | |
$this->connection = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->database, $this->username, $this->password); | |
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
$this->connection->exec("set names utf8"); | |
}catch(PDOException $exception){ | |
echo "Error: " . $exception->getMessage(); | |
} | |
return $this->connection; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment