3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php final class db extends PDO { private $engine; private $host; private $database; private $user; private $pass; private $charset; private static $link = null ; public static $VirtualDeletion = array( 'on' => false, 'Field' => '', 'Value' => '' ); public function __construct() { return self::i(); } public static function i() { if (!self::$link) return self::$link; $this->engine = 'mysql'; $this->host = 'localhost'; $this->database = ''; $this->user = 'root'; $this->pass = ''; $this->charset = 'utf8'; $dsn = $this->engine .":dbname=". $this->database .";charset=". $this->charset .";host=". $this->host; self::$link = parent::__construct( $dsn, $this->user, $this->pass ); /* PHP < 5.3.6 self::$link->exec("set names utf8"); */ return self::$link; } public function __destruct() { if(self::$link) { /* Estudar as implicações disto: if(PDO::inTransaction()) self::$link->commit(); */ self::$link = null; } } } /* ###### config.ini ###### db_driver=mysql db_user=root db_password=924892xp [dsn] host=localhost port=3306 dbname=localhost [db_options] PDO::MYSQL_ATTR_INIT_COMMAND=set names utf8 [db_attributes] ATTR_ERRMODE=ERRMODE_EXCEPTION ############ private static function getLink ( ) { if ( self :: $link ) { return self :: $link ; } $ini = _BASE_DIR . "config.ini" ; $parse = parse_ini_file ( $ini , true ) ; $driver = $parse [ "db_driver" ] ; $dsn = "${driver}:" ; $user = $parse [ "db_user" ] ; $password = $parse [ "db_password" ] ; $options = $parse [ "db_options" ] ; $attributes = $parse [ "db_attributes" ] ; foreach ( $parse [ "dsn" ] as $k => $v ) { $dsn .= "${k}=${v};" ; } self :: $link = new PDO ( $dsn, $user, $password, $options ) ; foreach ( $attributes as $k => $v ) { self :: $link -> setAttribute ( constant ( "PDO::{$k}" ) , constant ( "PDO::{$v}" ) ) ; } return self :: $link ; } public static function __callStatic ( $name, $args ) { $callback = array ( self :: getLink ( ), $name ) ; return call_user_func_array ( $callback , $args ) ; } */ ?>
Output for 5.1.0 - 7.1.0
Output for 5.0.0 - 5.0.5
Fatal error: Class 'PDO' not found in /in/OmDg6 on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CLASS in /in/OmDg6 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_CLASS in /in/OmDg6 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/OmDg6 on line 3
Process exited with code 255.