Skip to content

Instantly share code, notes, and snippets.

@wildroo
Created July 5, 2021 04:21
Show Gist options
  • Save wildroo/2ee19160ef9425d9ec186ba4a1585ca7 to your computer and use it in GitHub Desktop.
Save wildroo/2ee19160ef9425d9ec186ba4a1585ca7 to your computer and use it in GitHub Desktop.
DB Config PHP File
<?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