3v4l.org

run code in 300+ PHP versions simultaneously
<?php class database{ // @object, The PDO object private $pdo; private $db_connected, $error; private $stmt; public function __construct($host, $dbname, $user, $pass, $char_set="utf8"){ $dsn = 'mysql:dbname='.$dbname.';host='.$host.''; try{ $this->pdo = new PDO($dsn, $user, $pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES ".$char_set)); // We can now log any exceptions on Fatal error. $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Disable emulation of prepared statements, use REAL prepared statements instead. $this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $this->db_connected = true; }catch (PDOException $e){ die("Error! Could not connect to the database.<br />".$e->getMessage()); } } public function __destruct(){ $this->pdo = null; $this->db_connected = false; } public function query($query){ try{ $this->stmt = $this->pdo->prepare($query); }catch(PDOException $e){ if( _safemode_ ){ die("Error! Invalid Query.<br />".$query."<br />".$e->getMessage()); } else{ die("A fatal error occurred."); } } } public function bind($param, $value, $type = null){ if ( is_null($type) ){ switch(true){ case is_int($value): $type = PDO::PARAM_INT; break; case is_bool($value): $type = PDO::PARAM_BOOL; break; case is_null($value): $type = PDO::PARAM_NULL; break; default: $type = PDO::PARAM_STR; } } $this->stmt->bindValue($param, $value, $type); } public function execute(){ try{ $this->stmt->execute(); return true; }catch(PDOException $e){ $this->error = $e->getMessage(); return false; } } public function run(){ $this->execute(); } public function results(){ $this->execute(); return $this->stmt->fetchAll(PDO::FETCH_ASSOC); } public function single(){ $this->execute(); return $this->stmt->fetch(PDO::FETCH_ASSOC); } public function num_rows(){ return $this->stmt->rowCount(); } public function last_insert_id(){ return $this->pdo->lastInsertId(); } public function begin_transaction(){ return $this->pdo->beginTransaction(); } public function end_transaction(){ return $this->pdo->commit(); } public function cancel_transaction(){ return $this->pdo->rollBack(); } public function dump(){ return $this->stmt->debugDumpParams(); } }
Output for git.master, git.master_jit, rfc.property-hooks

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
51.45 ms | 401 KiB | 8 Q