3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
$username = myusername; $password = mypw; $host = "db4free.net:3306"; $dbname = mydbname; $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'); try { $db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options); } catch(PDOException $ex) { die("Failed to connect to the database: " . $ex->getMessage()); } <?php
Output for 4.3.0 - 5.4.32
$username = myusername; $password = mypw; $host = "db4free.net:3306"; $dbname = mydbname; $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'); try { $db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options); } catch(PDOException $ex) { die("Failed to connect to the database: " . $ex->getMessage()); } <?php