3v4l.org

run code in 300+ PHP versions simultaneously
<?php $db = new PDO("sqlite::memory:"); $db->setAttribute( # raise exceptions PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->query( # you already have a table "CREATE TABLE data (one INT, two INT, three INT, four INT, five INT);"); $stmt = $db->prepare( # prepare query, one placeholding ? for each column left of VALUES "INSERT INTO data (one, two, three, four, five) VALUES(?, ?, ?, ?, ?);"); foreach ([ [1,2,3,4,5], # a row from csv [6,7,8,9,0] # another row from csv ] as $row) { $stmt->execute($row); } $result = $db->query("SELECT * FROM data"); # show it was inserted while ($row = $result->fetch(PDO::FETCH_ASSOC)) { var_dump($row); } ?>
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array(5) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) ["four"]=> int(4) ["five"]=> int(5) } array(5) { ["one"]=> int(6) ["two"]=> int(7) ["three"]=> int(8) ["four"]=> int(9) ["five"]=> int(0) }
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
array(5) { ["one"]=> string(1) "1" ["two"]=> string(1) "2" ["three"]=> string(1) "3" ["four"]=> string(1) "4" ["five"]=> string(1) "5" } array(5) { ["one"]=> string(1) "6" ["two"]=> string(1) "7" ["three"]=> string(1) "8" ["four"]=> string(1) "9" ["five"]=> string(1) "0" }

preferences:
124.51 ms | 409 KiB | 5 Q