3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); /** * Created in PhpStorm. * User: 750430 * Date: 04/03/2016 * Time: 20:52 */ include __DIR__.'/db_settings.php'; // try/catch to connect to the db and create the database using a prepared statement if it doesn't exist. try{ $pdo = new PDO("mysql:host' . HOST.'; charset='.CHARSET.';port='.POST.'", $user, $pass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $pdo->prepare("CREATE DATABASE IF NOT EXISTS $db"); $stmt->execute(); $results["meta"]["feedback"] = "Database created."; return $results; } catch (PDOException $e) { echo 'Create DB failed: ' . $e->getMessage(); } try{ $stmt = $pdo->prepare("USE $db"); $stmt->execute(); $error = 'use db'; throw new Exception($error); } catch (PDOException $e) { echo 'DB use failed: ' . $e->getMessage(); } try{ $stmt = $pdo->query(DATABASE_INIT); $stmt->execute(); $error = 'create tables'; throw new Exception($error); } catch (PDOException $e) { echo 'Create tables failed: ' . $e->getMessage(); } echo ini_get('display_errors');
based on Ye4hH
Output for 7.0.5 - 7.2.6
Warning: include(/in/db_settings.php): failed to open stream: No such file or directory in /in/s24fs on line 11 Warning: include(): Failed opening '/in/db_settings.php' for inclusion (include_path='.:') in /in/s24fs on line 11 Notice: Undefined variable: user in /in/s24fs on line 15 Notice: Undefined variable: pass in /in/s24fs on line 15 Create DB failed: could not find driver Notice: Undefined variable: pdo in /in/s24fs on line 25 Fatal error: Uncaught Error: Call to a member function prepare() on null in /in/s24fs:25 Stack trace: #0 {main} thrown in /in/s24fs on line 25
Process exited with code 255.
Output for 7.0.0 - 7.0.4
Warning: include(/in/db_settings.php): failed to open stream: No such file or directory in /in/s24fs on line 11 Warning: include(): Failed opening '/in/db_settings.php' for inclusion (include_path='.:') in /in/s24fs on line 11 Notice: Undefined variable: user in /in/s24fs on line 15 Notice: Undefined variable: pass in /in/s24fs on line 15 Create DB failed: could not find driver Notice: Undefined variable: pdo in /in/s24fs on line 25 Fatal error: Uncaught Error: Call to a member function prepare() on unknown in /in/s24fs:25 Stack trace: #0 {main} thrown in /in/s24fs on line 25
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Warning: include(/in/db_settings.php): failed to open stream: No such file or directory in /in/s24fs on line 11 Warning: include(): Failed opening '/in/db_settings.php' for inclusion (include_path='.:') in /in/s24fs on line 11 Notice: Undefined variable: user in /in/s24fs on line 15 Notice: Undefined variable: pass in /in/s24fs on line 15 Create DB failed: could not find driver Notice: Undefined variable: pdo in /in/s24fs on line 25 Fatal error: Call to a member function prepare() on null in /in/s24fs on line 25
Process exited with code 255.
Output for 5.5.0 - 5.5.35
Warning: include(/in/db_settings.php): failed to open stream: No such file or directory in /in/s24fs on line 11 Warning: include(): Failed opening '/in/db_settings.php' for inclusion (include_path='.:') in /in/s24fs on line 11 Notice: Undefined variable: user in /in/s24fs on line 15 Notice: Undefined variable: pass in /in/s24fs on line 15 Create DB failed: could not find driver Notice: Undefined variable: pdo in /in/s24fs on line 25 Fatal error: Call to a member function prepare() on a non-object in /in/s24fs on line 25
Process exited with code 255.