Skip to content

Instantly share code, notes, and snippets.

@evaldas-raisutis
Created October 21, 2013 20:27
Show Gist options
  • Save evaldas-raisutis/7090390 to your computer and use it in GitHub Desktop.
Save evaldas-raisutis/7090390 to your computer and use it in GitHub Desktop.
PDO class
<?php
define("DBHOST", "");
define("DBNAME", "");
define("DBUSER", "");
define("DBPASS", "");
?>
<?php
require("config.live.php");
class Database {
private static $db;
private function __construct(){}
private function __clone(){}
public static function get_instance(){
if (! self::$db){
try{
global $dbhost, $dbname, $dbuser, $dbpass;
self::$db = new PDO("mysql:host=" . DBHOST . ";dbname=" . DBNAME . "", DBUSER, DBPASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
}
catch(PDOException $e){
die($e->getMessage());
}
}
return self::$db;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment