File: informix.php3

package info (click to toggle)
php3 3%3A3.0.18-0potato1.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,736 kB
  • ctags: 11,198
  • sloc: ansic: 108,120; sh: 2,512; php: 2,024; yacc: 1,887; makefile: 1,038; perl: 537; pascal: 238; awk: 90; cpp: 28; sql: 11
file content (338 lines) | stat: -rw-r--r-- 10,901 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<script language=PHP>
//
// test script to exercise basic PHP3 Informix driver functionality
// uses the ODS/SE 7.x stores7 demo database
// sept 1998 Danny.Heijl@cevi.be
//

function check_ifx($res) {
    $msg = ifx_error($res);
    if ($msg[0] == ' ')
      return 1;
   else 
      return 0;
}

$res = ifx_connect("stores7@demo_se","informix","informix");
if (!check_ifx($res)) {
    printf("ifx_connect : %s %s\n", ifx_error($res), ifx_errormsg());
}
if (! $res) {
    printf("can not connect to server\n");
    exit;
}
printf("+----------------------------------------+\n");
printf("|        query : 'select * from orders'  |\n");
printf("+----------------------------------------+\n");
$query = "select * from orders";
$resultid = ifx_query($query, $res, IFX_SCROLL);
if (!check_ifx($resultid)) {
    printf("ifx_query : %s:%s \n", ifx_error($res), ifx_errormsg());
}
if (! $resultid) {
   printf("ifx_query : bailing out \n");
   die;
}
printf("+----------------------------------------+\n");
printf("|      affected rows :                   |\n");
printf("+----------------------------------------+\n");
printf("Estimated number of rows : %d\n\n", ifx_affected_rows($resultid));
printf("+----------------------------------------+\n");
printf("|        Number of columns :             |\n");
printf("+----------------------------------------+\n");

printf("Number of columns = %d\n", ifx_num_fields($resultid));

printf("+----------------------------------------+\n");
printf("|        field types and properties :    |\n");
printf("+----------------------------------------+\n");

unset($types);
unset($props);
$types = ifx_fieldtypes($resultid);
$props = ifx_fieldproperties($resultid);
if ((! isset($types)) || (! isset($props))) {
    printf("ifx_fieldxxxx : %s\n", ifx_error($res));
    ifx_close($res);
    die;
}
for ($i = 0; $i < count($types); $i++) {
    $fname = key($types);
    printf("%s :\t type =  %s\n", $fname, $types[$fname]);
    printf("%s :\t properties =  %s\n", $fname, $props[$fname]);
    next($types);
    next($props);
}

// the quick way :
// ifx_htmltbl_resultid($resultid,"border=\"1\"");

// with more user control :
printf("+----------------------------------------+\n");
printf("|       in normal order :                |\n");
printf("+----------------------------------------+\n");
unset($row);
$row = ifx_fetch_row($resultid, "first");
while (is_array($row)) {
  for(reset($row); $fname = key($row); next($row)) {
        printf("%s=%s;", $fname, $row[$fname]);
   }
   printf("\n");
   $row = ifx_fetch_row($resultid, "next");
}

printf("Number of rows fetched so far : %d\n", ifx_num_rows($resultid));

printf("+----------------------------------------+\n");
printf("|       and now in reverse order :       |\n");
printf("+----------------------------------------+\n");
unset($row);
$row = ifx_fetch_row($resultid, "last");
while (is_array($row)) {
  for(reset($row); $fname = key($row); next($row)) {
        printf("%s=%s;", $fname, $row[$fname]);
   }
   printf("\n");
   $row = ifx_fetch_row($resultid, "previous");
}

printf("Number of rows fetched so far : %d\n", ifx_num_rows($resultid));

printf("+-----------------------------------------+\n");
printf("|         and now row number 10           |\n");
printf("+-----------------------------------------+\n");
unset($row);
$row = ifx_fetch_row($resultid, 10);
for(reset($row); $fname = key($row); next($row)) {
    printf("%s=%s;", $fname, $row[$fname]);
}
printf("\n\nResultid was : %d\n",$resultid);
ifx_free_result($resultid);

printf("\n\n\n********* and now prepare/do test *******\n\n\n");

printf("+----------------------------------------+\n");
printf("| prepare query : 'select * from orders' |\n");
printf("+----------------------------------------+\n");
$query = "select * from orders";
$resultid = ifx_prepare($query, $res, IFX_SCROLL);
if (!check_ifx($resultid)) {
    printf("ifx_prepare : %s:%s \n", ifx_error($res), ifx_errormsg());
}
if (! $resultid) {
   printf("ifx_prepare : bailing out \n");
   die;
}
printf("+----------------------------------------+\n");
printf("|      affected rows :                   |\n");
printf("+----------------------------------------+\n");
printf("Estimated number of rows : %d\n\n", ifx_affected_rows($resultid));
printf("+----------------------------------------+\n");
printf("|        Number of columns :             |\n");
printf("+----------------------------------------+\n");

printf("Number of columns = %d\n", ifx_num_fields($resultid));

printf("+----------------------------------------+\n");
printf("|        field types and properties :    |\n");
printf("+----------------------------------------+\n");

unset($types);
unset($props);
$types = ifx_fieldtypes($resultid);
$props = ifx_fieldproperties($resultid);
if ((! isset($types)) || (! isset($props))) {
    printf("ifx_fieldxxxx : %s\n", ifx_error($res));
    ifx_close($res);
    die;
}
for ($i = 0; $i < count($types); $i++) {
    $fname = key($types);
    printf("%s :\t type =  %s\n", $fname, $types[$fname]);
    printf("%s :\t properties =  %s\n", $fname, $props[$fname]);
    next($types);
    next($props);
}
printf("+----------------------------------------+\n");
printf("| execute query : 'select * from orders' |\n");
printf("+----------------------------------------+\n");
if (! ifx_do($resultid)) {
    printf("ifx_query : %s:%s \n", ifx_error($res), ifx_errormsg());
    printf("ifx_do : bailing out\n");
    die;
}
printf("+----------------------------------------+\n");

// the quick way :
// ifx_htmltbl_resultid($resultid,"border=\"1\"");

// with more user control :
printf("+----------------------------------------+\n");
printf("|       in normal order :                |\n");
printf("+----------------------------------------+\n");
unset($row);
$row = ifx_fetch_row($resultid, "first");
while (is_array($row)) {
  for(reset($row); $fname = key($row); next($row)) {
        printf("%s=%s;", $fname, $row[$fname]);
   }
   printf("\n");
   $row = ifx_fetch_row($resultid, "next");
}
printf("+----------------------------------------+\n");
printf("|       and now in reverse order :       |\n");
printf("+----------------------------------------+\n");
unset($row);
$row = ifx_fetch_row($resultid, "last");
while (is_array($row)) {
  for(reset($row); $fname = key($row); next($row)) {
        printf("%s=%s;", $fname, $row[$fname]);
   }
   printf("\n");
   $row = ifx_fetch_row($resultid, "previous");
}

printf("+-----------------------------------------+\n");
printf("|         and now row number 10           |\n");
printf("+-----------------------------------------+\n");
unset($row);
$row = ifx_fetch_row($resultid, 10);
for(reset($row); $fname = key($row); next($row)) {
    printf("%s=%s;", $fname, $row[$fname]);
}
printf("\n");
unset($row);

printf("\n\nResultid was : %d\n",$resultid);
ifx_free_result($resultid);

printf("\n");
printf("+-----------------------------------------+\n");
printf("|      some execute immediates(prepared)  |\n");
printf("+-----------------------------------------+\n");

$query = "create table testdh (k serial, d char(100), primary key (k))";
$resultid = ifx_prepare($query, $res);
if (!check_ifx($resultid)) {
    printf("ifx_prepare : %s:%s \n", ifx_error($res), ifx_errormsg());
}
if (! $resultid) {
   printf("ifx_prepare : bailing out \n");
   die;
}
printf("create table successfully prepared\n");
if (! ifx_do($resultid)) {
    printf("ifx_query : %s:%s \n", ifx_error($res), ifx_errormsg());
    printf("ifx_do : bailing out\n");
    die;
}
printf("create table successfully executed\n");
ifx_free_result($resultid);
printf("\n");
printf("+-----------------------------------------+\n");
printf("|      some inserts (unprepared)           |\n");
printf("+-----------------------------------------+\n");

for ($i = 1; $i < 20; $i++) {
    $query = sprintf(
                  "insert into testdh values (0,\"- this is row number %d -\")",
	           $i);
    echo $query . "\n";
    $rc = ifx_query($query, $res);
    if (! $rc) {
        printf("insert fails : %s:%s\n", ifx_error($res), ifx_errormsg());
        die;
    }
    ifx_free_result($rc);
}

printf("\n");
printf("+-----------------------------------------+\n");
printf("|      some updates (unprepared)           |\n");
printf("+-----------------------------------------+\n");

for ($i = 1; $i < 20; $i++) {
    $query = sprintf(
                  "update testdh set d = \"- this is still row " .
                  "number %d -\" where k = %d",
	           $i, $i);
    echo $query . "\n";
    $rc = ifx_query($query, $res);
    if (! $rc) {
        printf("update fails : %s:%s\n", ifx_error($res), ifx_errormsg());
        die;
    }
    ifx_free_result($rc);
}


printf("\n");
printf("+-----------------------------------------+\n");
printf("|      deleting inserted rows             |\n");
printf("+-----------------------------------------+\n");
$query = "delete from testdh";
$resultid = ifx_prepare($query, $res);
if (!check_ifx($resultid)) {
    printf("ifx_prepare : %s:%s \n", ifx_error($res), ifx_errormsg());
}
printf("estimate : %d rows will be deleted\n", ifx_affected_rows($resultid));
if (!ifx_do($resultid)) {
    printf("ifx_do : %s:%s \n", ifx_error($res), ifx_errormsg());
    die;
}
printf("%d rows successfully deleted\n", ifx_affected_rows($resultid));

$query = "drop table testdh";
$resultid = ifx_prepare($query, $res);
if (!check_ifx($resultid)) {
    printf("ifx_prepare : %s:%s \n", ifx_error($res), ifx_errormsg());
    die;
}
if (! $resultid) {
   printf("ifx_prepare : bailing out \n");
   die;
}
printf("drop table successfully prepared\n");
if (! ifx_do($resultid)) {
    printf("ifx_query : %s:%s \n", ifx_error($res), ifx_errormsg());
    printf("ifx_do : bailing out\n");
    die;
}
printf("drop table successfully executed\n");
ifx_free_result($resultid);

printf("\n");
printf("+-----------------------------------------+\n");
printf("|      some execute immediates(unprepared)|\n");
printf("+-----------------------------------------+\n");
$query = "create table testdh (k serial, d char(100), primary key (k))";
$resultid = ifx_query($query, $res);
if (!check_ifx($resultid)) {
    printf("ifx_query : %s:%s \n", ifx_error($res), ifx_errormsg());
}
if (! $resultid) {
   printf("ifx_query : bailing out \n");
   die;
}
printf("create table successfully executed\n");
ifx_free_result($resultid);

$query = "drop table testdh";
$resultid = ifx_query($query, $res);
if (!check_ifx($resultid)) {
    printf("ifx_query : %s:%s \n", ifx_error($res), ifx_errormsg());
}
if (! $resultid) {
   printf("ifx_query : bailing out \n");
   die;
}
printf("drop table successfully executed\n");
ifx_free_result($resultid);

ifx_close($res);
printf("+-----------------------------------------+\n");
printf("|      --------  end ---------            |\n");
printf("+-----------------------------------------+\n");
</script>