3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $db = new pdo('sqlite::memory:', null, null, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]); $db->exec('create table foo( n INT UNIQUE );'); $n = 1; $insert = $db->prepare('insert into foo(n) values(:n)'); $insert->bindParam('n', $n); for ($i=0; $i<5; $i++) { try { $insert->execute(); } catch (PDOException $e) { // assuming duplicate $n++; } } var_dump($db->query('select * from foo')->fetchAll(PDO::FETCH_ASSOC));
based on BItc2
Output for 5.6.0 - 7.3.0alpha1
array(3) { [0]=> array(1) { ["n"]=> string(1) "1" } [1]=> array(1) { ["n"]=> string(1) "2" } [2]=> array(1) { ["n"]=> string(1) "3" } }