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