Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author Jon Logan
- *
- *
- */
- class mySQL {
- /**
- * @var PDO is the only reference to the PDO Object.
- */
- private static $objInstance;
- /**
- * @var string is the database server location.
- */
- private static $_host = 'localhost';
- /**
- * @var string is the mySQL user.
- */
- private static $_username = 'thefamous';
- /**
- * @var string is the mySQL password.
- */
- private static $_password = 'Gre9b6WfqYnuae8J';
- /**
- * @var string is the database name.
- */
- private static $_db = 'thefamous';
- private function __construct() { }
- private function __clone() {}
- /**
- * Returns DB instance or create initial connection
- * @param
- * @return $objInstance;
- * @throws MySQLConnectionException
- */
- public static function getInstance () {
- if(!self::$objInstance){
- try {
- self::$objInstance = new PDO('mysql:dbname='.self::$_db.';host='.self::$_host,
- self::$_username, self::$_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));
- self::$objInstance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch(PDOException $e) {
- throw new MySQLConnectionException($e);
- }
- }
- return self::$objInstance;
- }
- /**
- * Passes on any static calls to this class onto the singleton PDO instance
- * @param $chrMethod, $arrArguments
- * @return $mix
- */
- final public static function __callStatic($chrMethod,$arrArguments) {
- $objInstance = self::getInstance();
- return call_user_func_array(array($objInstance,$chrMethod),$arrArguments);
- }
- /**
- * Returns a PDOStatement object
- * @param query
- * @return PDOStatement
- */
- public static function prepare($a) {
- return self::getInstance()->prepare($a);
- }
- /**
- * Returns a PDOStatement object
- * @param query
- * @return PDOStatement
- */
- public static function exec($a) {
- return self::getInstance()->exec($a);
- }
- /**
- * Returns a PDOStatement object
- * @param query
- * @return PDOStatement
- */
- public static function execute($a) {
- return self::getInstance()->exec($a);
- }
- /**
- * Returns a PDOStatement object
- * @param query
- * @return PDOStatement
- */
- public static function query($a) {
- $b = self::getInstance()->query($a);
- return $b;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement