3v4l.org

run code in 300+ PHP versions simultaneously
<?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']]); }
Output for 8.1.0 - 8.1.9
Warning: Undefined variable $dsn in /in/FWKgf on line 4 Warning: Undefined variable $user in /in/FWKgf on line 4 Warning: Undefined variable $pass in /in/FWKgf on line 4 Warning: Undefined variable $options in /in/FWKgf on line 4 Deprecated: PDO::__construct(): Passing null to parameter #1 ($dsn) of type string is deprecated in /in/FWKgf on line 4 Fatal error: Uncaught PDOException: PDO::__construct(): Argument #1 ($dsn) must be a valid 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.
Output for 8.0.0 - 8.0.22
Warning: Undefined variable $dsn in /in/FWKgf on line 4 Warning: Undefined variable $user in /in/FWKgf on line 4 Warning: Undefined variable $pass in /in/FWKgf on line 4 Warning: Undefined variable $options in /in/FWKgf on line 4 Fatal error: Uncaught PDOException: PDO::__construct(): Argument #1 ($dsn) must be a valid 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.
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.30
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.
Output for 7.3.32 - 7.3.33
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.

preferences:
61.95 ms | 414 KiB | 5 Q