3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php try { $hostname = "localhost"; $dbname = "mydatabase"; $username = "myusername"; $pw = "mypassword"; $db = new PDO ("mysql:host=$hostname;dbname=$dbname","$username","$pw"); } catch (PDOException $e) { echo "Failed to get DB handle: " . $e->getMessage() . "\n"; exit; } echo 'Hello'; $section = 1; $userID = 99; $clean_html = 'test !!!!!!!!!'; $stmt = $db->prepare("INSERT INTO userContent (section, author, content) VALUES (:section, :author, :content)"); $stmt->bindValue(':section', $section, PDO::PARAM_INT); $stmt->bindValue(':author', $userID, PDO::PARAM_INT); $stmt->bindValue(':content', $clean_html, PDO::PARAM_STR); if (!$stmt) { echo "\nPDO::errorInfo():\n"; print_r($dbh->errorInfo()); } echo 'Worked'; ?>
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.2.6
Failed to get DB handle: could not find driver
Output for hhvm-3.15.4
Failed to get DB handle: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)