Skip to content

Instantly share code, notes, and snippets.

@igoralves1
Created December 5, 2016 15:44
Show Gist options
  • Save igoralves1/008c59d32bf7a3957404dd3a57ad7a92 to your computer and use it in GitHub Desktop.
Save igoralves1/008c59d32bf7a3957404dd3a57ad7a92 to your computer and use it in GitHub Desktop.
db Class ... constructor
//This is a constructor that will return a handle to deal with a connection to the database MySQL
public function __construct() {
$this->dsn = "xxxxxxxx";
$this->username = "xxxxxxx";
$this->password = "xxxxx";
$this->db = "xxxxx";
try {
$this->conn = new PDO("mysql:host=$this->dsn; dbname=$this->db", $this->username, $this->password);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}// End of try
catch(PDOException $e){
echo $e->getMessage();
$this->conn = null;
die();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment