<?php
$pdo = new pdo('sqlite::memory:', null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
$pdo->exec('create table foo(id int primary key, letter text)');
$ids = insert($pdo, 'insert into foo(letter) values(?), (?), (?)', ['a', 'b', 'c']);
var_dump($ids, $pdo->query('select * from foo')->fetchAll(PDO::FETCH_ASSOC));
function insert($pdo, string $sql, array $params = []) : array {
if (stripos($sql, 'INSERT') !== 0) {
throw new InvalidArgumentException('##LG_NOT_AN_INSERT_STATEMENT##');
}
//$pdo = $this->getAdapter()->getConnection();
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$count = $stmt->rowCount();
$last = $pdo->lastInsertId();
return range($last - $count, $last);
}
- Output for 7.0.0 - 7.0.33, 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, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- array(4) {
[0]=>
int(0)
[1]=>
int(1)
[2]=>
int(2)
[3]=>
int(3)
}
array(3) {
[0]=>
array(2) {
["id"]=>
NULL
["letter"]=>
string(1) "a"
}
[1]=>
array(2) {
["id"]=>
NULL
["letter"]=>
string(1) "b"
}
[2]=>
array(2) {
["id"]=>
NULL
["letter"]=>
string(1) "c"
}
}
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array(4) {
[0]=>
int(0)
[1]=>
int(1)
[2]=>
int(2)
[3]=>
int(3)
}
array(3) {
[0]=>
array(2) {
["id"]=>
NULL
["letter"]=>
string(1) "a"
}
[1]=>
array(2) {
["id"]=>
NULL
["letter"]=>
string(1) "b"
}
[2]=>
array(2) {
["id"]=>
NULL
["letter"]=>
string(1) "c"
}
}
- Output for 5.6.0 - 5.6.40
- Parse error: syntax error, unexpected ':', expecting '{' in /in/eLHO8 on line 10
Process exited with code 255.
preferences:
220.45 ms | 401 KiB | 291 Q