3v4l.org

run code in 300+ PHP versions simultaneously
<?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 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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.3.11, 4.4.0 - 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.

preferences:
267.32 ms | 401 KiB | 373 Q