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) { // assiming duplicate $n++; } }
based on df7gX
Output for 5.6.0 - 7.3.0alpha1