Created
October 21, 2013 20:27
-
-
Save evaldas-raisutis/7090390 to your computer and use it in GitHub Desktop.
PDO class
This file contains hidden or 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 | |
define("DBHOST", ""); | |
define("DBNAME", ""); | |
define("DBUSER", ""); | |
define("DBPASS", ""); | |
?> |
This file contains hidden or 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 | |
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