xref: /php-src/ext/pdo_sqlite/tests/bug78192.phpt (revision 74859783)
1--TEST--
2PDO SQLite Bug #78192 SegFault when reuse statement after schema change
3--EXTENSIONS--
4pdo_sqlite
5--FILE--
6<?php
7$connection = new \PDO('sqlite::memory:');
8$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
9$connection->query('CREATE TABLE user (id INTEGER PRIMARY KEY NOT NULL, name VARCHAR(255) NOT NULL)');
10
11$stmt = $connection->prepare('INSERT INTO user (id, name) VALUES(:id, :name)');
12$stmt->execute([
13    'id'   => 10,
14    'name' => 'test',
15]);
16
17$stmt = $connection->prepare('SELECT * FROM user WHERE id = :id');
18$stmt->execute(['id' => 10]);
19var_dump($stmt->fetchAll(\PDO::FETCH_ASSOC));
20
21$connection->query('ALTER TABLE user ADD new_col VARCHAR(255)');
22$stmt->execute(['id' => 10]);
23var_dump($stmt->fetchAll(\PDO::FETCH_ASSOC));
24?>
25--EXPECT--
26array(1) {
27  [0]=>
28  array(2) {
29    ["id"]=>
30    int(10)
31    ["name"]=>
32    string(4) "test"
33  }
34}
35array(1) {
36  [0]=>
37  array(3) {
38    ["id"]=>
39    int(10)
40    ["name"]=>
41    string(4) "test"
42    ["new_col"]=>
43    NULL
44  }
45}
46