xref: /PHP-7.0/ext/odbc/tests/bug47803.phpt (revision c9778d3e)
1--TEST--
2Bug #47803 Executing prepared statements is succesfull only for the first two statements
3--SKIPIF--
4<?php include 'skipif.inc'; ?>
5--FILE--
6<?php
7
8include dirname(__FILE__) . "/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==DONE==
92--EXPECT--
93array(3) {
94  ["PAR_ID"]=>
95  string(1) "1"
96  ["PAR_INT"]=>
97  string(2) "14"
98  ["PAR_CHR"]=>
99  string(6) "test 1"
100}
101array(3) {
102  ["PAR_ID"]=>
103  string(1) "2"
104  ["PAR_INT"]=>
105  string(2) "30"
106  ["PAR_CHR"]=>
107  string(6) "test 2"
108}
109array(3) {
110  ["PAR_ID"]=>
111  string(1) "3"
112  ["PAR_INT"]=>
113  string(1) "7"
114  ["PAR_CHR"]=>
115  string(6) "test 3"
116}
117array(3) {
118  ["PAR_ID"]=>
119  string(1) "4"
120  ["PAR_INT"]=>
121  string(1) "7"
122  ["PAR_CHR"]=>
123  string(6) "test 4"
124}
125array(3) {
126  ["PAR_ID"]=>
127  string(1) "5"
128  ["PAR_INT"]=>
129  string(1) "0"
130  ["PAR_CHR"]=>
131  string(6) "test 5"
132}
133array(3) {
134  ["PAR_ID"]=>
135  string(2) "10"
136  ["PAR_INT"]=>
137  string(8) "20140620"
138  ["PAR_CHR"]=>
139  string(7) "test 10"
140}
141array(3) {
142  ["PAR_ID"]=>
143  string(1) "9"
144  ["PAR_INT"]=>
145  string(8) "20140201"
146  ["PAR_CHR"]=>
147  string(6) "test 9"
148}
149array(3) {
150  ["PAR_ID"]=>
151  string(1) "8"
152  ["PAR_INT"]=>
153  string(8) "20140201"
154  ["PAR_CHR"]=>
155  string(6) "test 8"
156}
157array(3) {
158  ["PAR_ID"]=>
159  string(1) "7"
160  ["PAR_INT"]=>
161  string(8) "20130901"
162  ["PAR_CHR"]=>
163  string(6) "test 7"
164}
165array(3) {
166  ["PAR_ID"]=>
167  string(1) "7"
168  ["PAR_INT"]=>
169  string(8) "20130901"
170  ["PAR_CHR"]=>
171  string(6) "test 7"
172}
173==DONE==
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