xref: /PHP-7.3/ext/pdo_sqlite/tests/bug78192.phpt (revision 05c00a83)
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--EXPECT--
27array(1) {
28  [0]=>
29  array(2) {
30    ["id"]=>
31    string(2) "10"
32    ["name"]=>
33    string(4) "test"
34  }
35}
36array(1) {
37  [0]=>
38  array(3) {
39    ["id"]=>
40    string(2) "10"
41    ["name"]=>
42    string(4) "test"
43    ["new_col"]=>
44    NULL
45  }
46}
47