1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <?php // Last Update:2013/11/28 23:10:43 class Mysql { private static $db = null; /* * Refenenced by: http://tw1.php.net/manual/en/class.pdo.php#97682 */ public static function get_db(){ if( self::$db ){ return self::$db; } $setting = parse_ini_file("connect.ini"); $user = $setting['username']; $passwd = $setting['password']; //$hash = exec("git log --pretty=format:'%h' -n 1"); $database = 'mysql'; try{ self::$db = new PDO( "mysql:host=localhost;dbname=" . $database, $user, $passwd ); } catch ( PDOException $e ){ print "Error!: " . $e->getMessage() . "<br/>"; die(); } return self::$db; } public static function __callStatic( $name, $args){ $callback = array( self::get_db(), $name ); var_dump($args); return call_user_func_array( $callback, $args ); } public function __destruct(){ //Debug::func_end("link for $this->func_name"); } } |
Direct link: https://paste.plurk.com/show/1732077