A php killer game implementation
at master 1.1 kB view raw
1<?php 2 3define('DB_HOST', 'localhost'); 4define('DB_NAME', 'your student tag'); 5define('DB_USER', 'your student tag'); 6define('DB_PASS', 'your password'); 7define('DB_CHAR', 'utf8'); 8 9class DB 10{ 11 protected static $instance = null; 12 13 final private function __construct() {} 14 final private function __clone() {} 15 16 public static function instance() 17 { 18 if (self::$instance === null) 19 { 20 $opt = array( 21 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, 22 PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, 23 PDO::ATTR_EMULATE_PREPARES => TRUE, 24 PDO::ATTR_STATEMENT_CLASS => array('myPDOStatement'), 25 ); 26 $dsn = 'mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset='.DB_CHAR; 27 self::$instance = new PDO($dsn, DB_USER, DB_PASS, $opt); 28 } 29 return self::$instance; 30 } 31 public static function __callStatic($method, $args) { 32 return call_user_func_array(array(self::instance(), $method), $args); 33 } 34} 35 36class myPDOStatement extends PDOStatement 37{ 38 function texecute($data = array()) 39 { 40 parent::execute($data); 41 return $this; 42 } 43}