3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // @see https://gist.github.com/adrian-enspired/385c6830ba2932bc36a2 $db = new PDO($dsn, $user, $pass, $options); $stmt = $db->prepare("INSERT INTO data (fetched_url, author) VALUES (?, ?)"); // example data $posts = [ [ 'data' => [ 'url' => 'https://hashphp.org', 'author_fullname' => 'alvisleet' ] ], [ 'data' => [ 'url' => 'https://hashphp.org', 'author_fullname' => 'alvisleet' ] ] ]; foreach ($posts as $post) { $stmt->execute([$post['data']['url'], $post['data']['author_fullname']]); }
based on oPeOd
Output for 7.1.25 - 7.3.3
Notice: Undefined variable: dsn in /in/FWKgf on line 4 Notice: Undefined variable: user in /in/FWKgf on line 4 Notice: Undefined variable: pass in /in/FWKgf on line 4 Notice: Undefined variable: options in /in/FWKgf on line 4 Fatal error: Uncaught PDOException: invalid data source name in /in/FWKgf:4 Stack trace: #0 /in/FWKgf(4): PDO->__construct('', NULL, NULL, NULL) #1 {main} thrown in /in/FWKgf on line 4
Process exited with code 255.