Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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