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