xref: /PHP-8.0/ext/odbc/tests/bug47803.phpt (revision f8d79582)
1--TEST--
2Bug #47803 Executing prepared statements is successful only for the first two statements
3--SKIPIF--
4<?php include 'skipif.inc'; ?>
5--FILE--
6<?php
7
8include __DIR__ . "/config.inc";
9
10$create_table = "CREATE TABLE FOO(
11        [PAR_ID] [int] NOT NULL,
12        [PAR_INT] [int] NULL,
13        [PAR_CHR] [varchar](500) NULL
14)";
15
16$inserts = "INSERT INTO FOO
17           ([PAR_ID]
18           ,[PAR_INT]
19           ,[PAR_CHR])
20     VALUES
21        (1,14,''),
22        (2,30,''),
23        (3,7,''),
24        (4,7,''),
25        (5,0,''),
26        (6,0,''),
27        (7,20130901,''),
28        (8,20140201,''),
29        (9,20140201,''),
30        (10,20140620,''),
31        (11,221,'')";
32
33
34date_default_timezone_set('Europe/Warsaw');
35
36$link = odbc_connect($dsn, $user, $pass);
37
38odbc_exec($link, 'CREATE DATABASE odbcTEST');
39odbc_exec($link, $create_table);
40odbc_exec($link, $inserts);
41
42$upd_params = array(
43    array('id'=>1, 'name'=>'test 1'),
44    array('id'=>2, 'name'=>'test 2'),
45    array('id'=>3, 'name'=>'test 3'),
46    array('id'=>4, 'name'=>'test 4'),
47    array('id'=>5, 'name'=>'test 5'),
48    array('id'=>10, 'name'=>'test 10'),
49    array('id'=>9, 'name'=>'test 9'),
50    array('id'=>8, 'name'=>'test 8'),
51    array('id'=>7, 'name'=>'test 7'),
52    array('id'=>6, 'name'=>'test 6'),
53);
54$sql = "UPDATE FOO
55     SET [PAR_CHR] = ?
56     WHERE [PAR_ID] = ?";
57$result = odbc_prepare($link, $sql);
58if (!$result) {
59    print ('[sql] prep: '.$sql);
60    goto out;
61}
62foreach ($upd_params as &$k) {
63    if(!odbc_execute($result, array($k['name'], $k['id']))) {
64        print ('[sql] exec: '."array({$k['name']}, {$k['id']})");
65        goto out;
66    }
67}
68odbc_free_result($result);
69
70$sql = "SELECT * FROM FOO WHERE [PAR_ID] = ?";
71$result = odbc_prepare($link, $sql);
72if (!$result) {
73    print ('[sql] prep: '.$sql);
74    goto out;
75}
76foreach ($upd_params as $k) {
77    if(!odbc_execute($result, array($k['id']))) {
78        print ('[sql] exec: '."array({$k['id']})");
79        goto out;
80    }
81    while (($r = odbc_fetch_array($result)) !== false) {
82        var_dump($r);
83    }
84}
85
86out:
87if ($result) odbc_free_result($result);
88odbc_close($link);
89
90?>
91--EXPECT--
92array(3) {
93  ["PAR_ID"]=>
94  string(1) "1"
95  ["PAR_INT"]=>
96  string(2) "14"
97  ["PAR_CHR"]=>
98  string(6) "test 1"
99}
100array(3) {
101  ["PAR_ID"]=>
102  string(1) "2"
103  ["PAR_INT"]=>
104  string(2) "30"
105  ["PAR_CHR"]=>
106  string(6) "test 2"
107}
108array(3) {
109  ["PAR_ID"]=>
110  string(1) "3"
111  ["PAR_INT"]=>
112  string(1) "7"
113  ["PAR_CHR"]=>
114  string(6) "test 3"
115}
116array(3) {
117  ["PAR_ID"]=>
118  string(1) "4"
119  ["PAR_INT"]=>
120  string(1) "7"
121  ["PAR_CHR"]=>
122  string(6) "test 4"
123}
124array(3) {
125  ["PAR_ID"]=>
126  string(1) "5"
127  ["PAR_INT"]=>
128  string(1) "0"
129  ["PAR_CHR"]=>
130  string(6) "test 5"
131}
132array(3) {
133  ["PAR_ID"]=>
134  string(2) "10"
135  ["PAR_INT"]=>
136  string(8) "20140620"
137  ["PAR_CHR"]=>
138  string(7) "test 10"
139}
140array(3) {
141  ["PAR_ID"]=>
142  string(1) "9"
143  ["PAR_INT"]=>
144  string(8) "20140201"
145  ["PAR_CHR"]=>
146  string(6) "test 9"
147}
148array(3) {
149  ["PAR_ID"]=>
150  string(1) "8"
151  ["PAR_INT"]=>
152  string(8) "20140201"
153  ["PAR_CHR"]=>
154  string(6) "test 8"
155}
156array(3) {
157  ["PAR_ID"]=>
158  string(1) "7"
159  ["PAR_INT"]=>
160  string(8) "20130901"
161  ["PAR_CHR"]=>
162  string(6) "test 7"
163}
164array(3) {
165  ["PAR_ID"]=>
166  string(1) "7"
167  ["PAR_INT"]=>
168  string(8) "20130901"
169  ["PAR_CHR"]=>
170  string(6) "test 7"
171}
172--CLEAN--
173<?php
174include 'config.inc';
175
176$conn = odbc_connect($dsn, $user, $pass);
177
178odbc_exec($conn, 'DROP TABLE FOO');
179odbc_exec($conn, 'DROP DATABASE odbcTEST');
180
181odbc_close($conn);
182
183?>
184