-
Notifications
You must be signed in to change notification settings - Fork 1
/
tmcpdo.php
494 lines (396 loc) · 17.4 KB
/
tmcpdo.php
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
<?php
include_once('config.php');
$pdo = new PDO($config_pdo_connection, $config_pdo_readonly_user, $config_pdo_readonly_password, $config_pdo_attributes);
function find_names($data)
{
global $pdo;
static $names = array('nid', 'rnid', 'n1id', 'n2id');
static $stmt = null;
if($stmt === null)
$stmt = $pdo->prepare("SELECT name FROM names WHERE cid = :cid AND nid = :nid");
foreach($names as $name)
{
if(array_key_exists($name, $data))
{
if($data[$name])
{
$stmt->bindValue(':cid', $data['cid'], PDO::PARAM_INT);
$stmt->bindValue(':nid', $data[$name], PDO::PARAM_INT);
$stmt->execute();
if($value = $stmt->fetch(PDO::FETCH_COLUMN))
$data[$name] = $value;
else
$data[$name] = "";
}
else
$data[$name] = "";
}
}
return $data;
}
function find_type($data)
{
global $pdo;
static $stmt = null;
if($stmt === null)
$stmt = $pdo->prepare("SELECT tdesc FROM types WHERE class = :class AND tcd = :tcd AND stcd = :stcd");
$stmt->bindValue(':class', $data['class'], PDO::PARAM_STR);
$stmt->bindValue(':tcd', $data['tcd'], PDO::PARAM_INT);
$stmt->bindValue(':stcd', $data['stcd'], PDO::PARAM_INT);
$stmt->execute();
if($name = $stmt->fetch(PDO::FETCH_COLUMN))
return $name;
else
return "";
}
function find_location($table, $cid, $tabcd, $lcd)
{
global $pdo;
static $stmts = array('locationcodes' => null, 'points' => null, 'poffsets' => null, 'segments' => null, 'soffsets' => null, 'roads' => null, 'administrativearea' => null, 'otherareas' => null);
if(!array_key_exists($table, $stmts))
return false;
if($stmts[$table] === null)
$stmts[$table] = $pdo->prepare("SELECT * FROM $table WHERE cid = :cid AND tabcd = :tabcd AND lcd = :lcd");
$stmts[$table]->bindValue(':cid', $cid, PDO::PARAM_INT);
$stmts[$table]->bindValue(':tabcd', $tabcd, PDO::PARAM_INT);
$stmts[$table]->bindValue(':lcd', $lcd, PDO::PARAM_INT);
$stmts[$table]->execute();
if(!($data = $stmts[$table]->fetch(PDO::FETCH_ASSOC)))
return false;
return find_names($data);
}
function find_road($data)
{
while(($data['roa_lcd'] == 0) && ($data['seg_lcd'] != 0))
{
$data = find_location('segments', $data['cid'], $data['tabcd'], $data['seg_lcd']);
if(!$data)
return 0;
}
return find_location('roads', $data['cid'], $data['tabcd'], $data['roa_lcd']);
}
function find_links($data)
{
$links = array();
if(array_key_exists('pol_lcd', $data) && $data['pol_lcd'] && ($link = find_location('administrativearea', $data['cid'], $data['tabcd'], $data['pol_lcd'])))
$links['pol_lcd'] = $link;
if(array_key_exists('oth_lcd', $data) && $data['oth_lcd'] && ($link = find_location('otherareas', $data['cid'], $data['tabcd'], $data['oth_lcd'])))
$links['oth_lcd'] = $link;
if(array_key_exists('seg_lcd', $data) && $data['seg_lcd'] && ($link = find_location('segments', $data['cid'], $data['tabcd'], $data['seg_lcd'])))
$links['seg_lcd'] = $link;
if(array_key_exists('roa_lcd', $data) && $data['roa_lcd'] && ($link = find_location('roads', $data['cid'], $data['tabcd'], $data['roa_lcd'])))
$links['roa_lcd'] = $link;
if(array_key_exists('neg_off_lcd', $data) && $data['neg_off_lcd'] && ($link = find_location(($data['class'] == 'P' ? 'points' : 'segments'), $data['cid'], $data['tabcd'], $data['neg_off_lcd'])))
$links['neg_off_lcd'] = $link;
if(array_key_exists('pos_off_lcd', $data) && $data['pos_off_lcd'] && ($link = find_location(($data['class'] == 'P' ? 'points' : 'segments'), $data['cid'], $data['tabcd'], $data['pos_off_lcd'])))
$links['pos_off_lcd'] = $link;
if(array_key_exists('interruptsroad', $data) && $data['interruptsroad'] && ($link = find_location('points', $data['cid'], $data['tabcd'], $data['interruptsroad'])))
$links['interruptsroad'] = $link;
return $links;
}
function find_inter($data)
{
global $pdo;
static $stmt = null;
if($stmt === null)
$stmt = $pdo->prepare("SELECT * FROM points WHERE xcoord = :xcoord AND ycoord = :ycoord ORDER BY cid, tabcd, lcd");
if($data['class'] == 'P')
{
$stmt->bindValue(':xcoord', $data['xcoord']);
$stmt->bindValue(':ycoord', $data['ycoord']);
$stmt->execute();
if($inters = $stmt->fetchAll(PDO::FETCH_ASSOC))
return array_map("find_names", $inters);
}
return array();
}
function find_segment_points($data)
{
global $pdo;
static $first = null;
static $next = null;
if($first === null)
$first = $pdo->prepare("SELECT points.*, poffsets.neg_off_lcd, poffsets.pos_off_lcd FROM points, poffsets WHERE points.cid = :cid_a AND poffsets.cid = :cid_b AND points.tabcd = :tabcd_a AND poffsets.tabcd = :tabcd_b AND points.lcd = poffsets.lcd AND points.seg_lcd = :lcd_a AND NOT EXISTS (SELECT * FROM points WHERE cid = :cid_c AND tabcd = :tabcd_c AND seg_lcd = :lcd_b AND lcd = poffsets.neg_off_lcd)");
if($next === null)
$next = $pdo->prepare("SELECT points.*, poffsets.neg_off_lcd, poffsets.pos_off_lcd FROM points, poffsets WHERE points.cid = :cid_a AND poffsets.cid = :cid_b AND points.tabcd = :tabcd_a AND poffsets.tabcd = :tabcd_b AND points.lcd = :lcd_a AND poffsets.lcd = :lcd_b AND points.seg_lcd = :lcd_c");
$first->bindValue(':cid_a', $data['cid'], PDO::PARAM_INT);
$first->bindValue(':cid_b', $data['cid'], PDO::PARAM_INT);
$first->bindValue(':cid_c', $data['cid'], PDO::PARAM_INT);
$first->bindValue(':tabcd_a', $data['tabcd'], PDO::PARAM_INT);
$first->bindValue(':tabcd_b', $data['tabcd'], PDO::PARAM_INT);
$first->bindValue(':tabcd_c', $data['tabcd'], PDO::PARAM_INT);
$first->bindValue(':lcd_a', $data['lcd'], PDO::PARAM_INT);
$first->bindValue(':lcd_b', $data['lcd'], PDO::PARAM_INT);
$next->bindValue(':cid_a', $data['cid'], PDO::PARAM_INT);
$next->bindValue(':cid_b', $data['cid'], PDO::PARAM_INT);
$next->bindValue(':tabcd_a', $data['tabcd'], PDO::PARAM_INT);
$next->bindValue(':tabcd_b', $data['tabcd'], PDO::PARAM_INT);
$next->bindValue(':lcd_c', $data['lcd'], PDO::PARAM_INT);
$points = array();
$first->execute();
if($point = $first->fetch(PDO::FETCH_ASSOC))
{
for(;;)
{
$point = find_names($point);
$points[] = $point;
$next->bindValue(':lcd_a', $point['pos_off_lcd'], PDO::PARAM_INT);
$next->bindValue(':lcd_b', $point['pos_off_lcd'], PDO::PARAM_INT);
$next->execute();
if(!($point = $next->fetch(PDO::FETCH_ASSOC)))
break;
}
}
return $points;
}
function find_road_points($data)
{
global $pdo;
static $rfirst = null;
static $rnext = null;
static $lfirst = null;
static $lnext = null;
$segs = array();
if($data['tcd'] == 2)
{
if($rfirst === null)
$rfirst = $pdo->prepare("SELECT points.*, poffsets.neg_off_lcd, poffsets.pos_off_lcd FROM points, poffsets WHERE points.cid = :cid_a AND poffsets.cid = :cid_b AND points.tabcd = :tabcd_a AND poffsets.tabcd = :tabcd_b AND points.lcd = poffsets.lcd AND (points.roa_lcd = :lcd_a OR EXISTS (SELECT * FROM segments WHERE cid = :cid_c AND tabcd = :tabcd_c AND roa_lcd = :lcd_b AND lcd = points.seg_lcd)) LIMIT 1");
if($rnext === null)
$rnext = $pdo->prepare("SELECT points.*, poffsets.neg_off_lcd, poffsets.pos_off_lcd FROM points, poffsets WHERE points.cid = :cid_a AND poffsets.cid = :cid_b AND points.tabcd = :tabcd_a AND poffsets.tabcd = :tabcd_b AND points.lcd = :lcd_a AND poffsets.lcd = :lcd_b");
$rfirst->bindValue(':cid_a', $data['cid'], PDO::PARAM_INT);
$rfirst->bindValue(':cid_b', $data['cid'], PDO::PARAM_INT);
$rfirst->bindValue(':cid_c', $data['cid'], PDO::PARAM_INT);
$rfirst->bindValue(':tabcd_a', $data['tabcd'], PDO::PARAM_INT);
$rfirst->bindValue(':tabcd_b', $data['tabcd'], PDO::PARAM_INT);
$rfirst->bindValue(':tabcd_c', $data['tabcd'], PDO::PARAM_INT);
$rfirst->bindValue(':lcd_a', $data['lcd'], PDO::PARAM_INT);
$rfirst->bindValue(':lcd_b', $data['lcd'], PDO::PARAM_INT);
$rnext->bindValue(':cid_a', $data['cid'], PDO::PARAM_INT);
$rnext->bindValue(':cid_b', $data['cid'], PDO::PARAM_INT);
$rnext->bindValue(':tabcd_a', $data['tabcd'], PDO::PARAM_INT);
$rnext->bindValue(':tabcd_b', $data['tabcd'], PDO::PARAM_INT);
$rfirst->execute();
if($first = $point = $rfirst->fetch(PDO::FETCH_ASSOC))
{
$points = array();
for(;;)
{
$point = find_names($point);
$points[] = $point;
if($point['pos_off_lcd'] == $first['lcd'])
break;
$rnext->bindValue(':lcd_a', $point['pos_off_lcd'], PDO::PARAM_INT);
$rnext->bindValue(':lcd_b', $point['pos_off_lcd'], PDO::PARAM_INT);
$rnext->execute();
if(!($point = $rnext->fetch(PDO::FETCH_ASSOC)))
break;
}
$segs[] = $points;
}
}
else
{
if($lfirst === null)
$lfirst = $pdo->prepare("SELECT points.*, poffsets.neg_off_lcd, poffsets.pos_off_lcd FROM points, poffsets WHERE points.cid = :cid_a AND poffsets.cid = :cid_b AND points.tabcd = :tabcd_a AND poffsets.tabcd = :tabcd_b AND points.lcd = poffsets.lcd AND poffsets.neg_off_lcd = '0' AND (points.roa_lcd = :lcd_a OR EXISTS (SELECT * FROM segments WHERE cid = :cid_c AND tabcd = :tabcd_c AND roa_lcd = :lcd_b AND lcd = points.seg_lcd))");
if($lnext === null)
$lnext = $pdo->prepare("SELECT points.*, poffsets.neg_off_lcd, poffsets.pos_off_lcd FROM points, poffsets WHERE points.cid = :cid_a AND poffsets.cid = :cid_b AND points.tabcd = :tabcd_a AND poffsets.tabcd = :tabcd_b AND points.lcd = :lcd_a AND poffsets.lcd = :lcd_b");
$lfirst->bindValue(':cid_a', $data['cid'], PDO::PARAM_INT);
$lfirst->bindValue(':cid_b', $data['cid'], PDO::PARAM_INT);
$lfirst->bindValue(':cid_c', $data['cid'], PDO::PARAM_INT);
$lfirst->bindValue(':tabcd_a', $data['tabcd'], PDO::PARAM_INT);
$lfirst->bindValue(':tabcd_b', $data['tabcd'], PDO::PARAM_INT);
$lfirst->bindValue(':tabcd_c', $data['tabcd'], PDO::PARAM_INT);
$lfirst->bindValue(':lcd_a', $data['lcd'], PDO::PARAM_INT);
$lfirst->bindValue(':lcd_b', $data['lcd'], PDO::PARAM_INT);
$lnext->bindValue(':cid_a', $data['cid'], PDO::PARAM_INT);
$lnext->bindValue(':cid_b', $data['cid'], PDO::PARAM_INT);
$lnext->bindValue(':tabcd_a', $data['tabcd'], PDO::PARAM_INT);
$lnext->bindValue(':tabcd_b', $data['tabcd'], PDO::PARAM_INT);
$lfirst->execute();
while($point = $lfirst->fetch(PDO::FETCH_ASSOC))
{
$points = array();
for(;;)
{
$point = find_names($point);
$points[] = $point;
$lnext->bindValue(':lcd_a', $point['pos_off_lcd'], PDO::PARAM_INT);
$lnext->bindValue(':lcd_b', $point['pos_off_lcd'], PDO::PARAM_INT);
$lnext->execute();
if(!($point = $lnext->fetch(PDO::FETCH_ASSOC)))
break;
}
$segs[] = $points;
}
}
return $segs;
}
function find_rs_segments($data)
{
global $pdo;
static $rfirst = null;
static $rnext = null;
static $lfirst = null;
static $lnext = null;
$segments = array();
if($data['tcd'] == 2)
{
if($rfirst === null)
$rfirst = $pdo->prepare("SELECT segments.*, soffsets.neg_off_lcd, soffsets.pos_off_lcd FROM segments, soffsets WHERE segments.cid = :cid_a AND soffsets.cid = :cid_b AND segments.tabcd = :tabcd_a AND soffsets.tabcd = :tabcd_b AND segments.lcd = soffsets.lcd AND (segments.roa_lcd = :lcd_a OR EXISTS (SELECT * FROM segments WHERE cid = :cid_c AND tabcd = :tabcd_c AND roa_lcd = :lcd_b AND lcd = segments.seg_lcd))");
if($rnext === null)
$rnext = $pdo->prepare("SELECT segments.*, soffsets.neg_off_lcd, soffsets.pos_off_lcd FROM segments, soffsets WHERE segments.cid = :cid_a AND soffsets.cid = :cid_b AND segments.tabcd = :tabcd_a AND soffsets.tabcd = :tabcd_b AND segments.lcd = :lcd_a AND soffsets.lcd = :lcd_b");
$rfirst->bindValue(':cid_a', $data['cid'], PDO::PARAM_INT);
$rfirst->bindValue(':cid_b', $data['cid'], PDO::PARAM_INT);
$rfirst->bindValue(':cid_c', $data['cid'], PDO::PARAM_INT);
$rfirst->bindValue(':tabcd_a', $data['tabcd'], PDO::PARAM_INT);
$rfirst->bindValue(':tabcd_b', $data['tabcd'], PDO::PARAM_INT);
$rfirst->bindValue(':tabcd_c', $data['tabcd'], PDO::PARAM_INT);
$rfirst->bindValue(':lcd_a', $data['lcd'], PDO::PARAM_INT);
$rfirst->bindValue(':lcd_b', $data['lcd'], PDO::PARAM_INT);
$rnext->bindValue(':cid_a', $data['cid'], PDO::PARAM_INT);
$rnext->bindValue(':cid_b', $data['cid'], PDO::PARAM_INT);
$rnext->bindValue(':tabcd_a', $data['tabcd'], PDO::PARAM_INT);
$rnext->bindValue(':tabcd_b', $data['tabcd'], PDO::PARAM_INT);
$rfirst->execute();
if($first = $segment = $rfirst->fetch(PDO::FETCH_ASSOC))
{
$segments = array();
for(;;)
{
$segment = find_names($segment);
$segments[] = $segment;
if($segment['pos_off_lcd'] == $first['lcd'])
break;
$rnext->bindValue(':lcd_a', $segment['pos_off_lcd'], PDO::PARAM_INT);
$rnext->bindValue(':lcd_b', $segment['pos_off_lcd'], PDO::PARAM_INT);
$rnext->execute();
if(!($segment = $rnext->fetch(PDO::FETCH_ASSOC)))
break;
}
}
}
else
{
if($lfirst === null)
$lfirst = $pdo->prepare("SELECT segments.*, soffsets.neg_off_lcd, soffsets.pos_off_lcd FROM segments, soffsets WHERE segments.cid = :cid_a AND soffsets.cid = :cid_b AND segments.tabcd = :tabcd_a AND soffsets.tabcd = :tabcd_b AND segments.lcd = soffsets.lcd AND soffsets.neg_off_lcd = '0' AND (segments.roa_lcd = :lcd_a OR EXISTS (SELECT * FROM segments WHERE cid = :cid_c AND tabcd = :tabcd_c AND roa_lcd = :lcd_b AND lcd = segments.seg_lcd))");
if($lnext === null)
$lnext = $pdo->prepare("SELECT segments.*, soffsets.neg_off_lcd, soffsets.pos_off_lcd FROM segments, soffsets WHERE segments.cid = :cid_a AND soffsets.cid = :cid_b AND segments.tabcd = :tabcd_a AND soffsets.tabcd = :tabcd_b AND segments.lcd = :lcd_a AND soffsets.lcd = :lcd_b");
$lfirst->bindValue(':cid_a', $data['cid'], PDO::PARAM_INT);
$lfirst->bindValue(':cid_b', $data['cid'], PDO::PARAM_INT);
$lfirst->bindValue(':cid_c', $data['cid'], PDO::PARAM_INT);
$lfirst->bindValue(':tabcd_a', $data['tabcd'], PDO::PARAM_INT);
$lfirst->bindValue(':tabcd_b', $data['tabcd'], PDO::PARAM_INT);
$lfirst->bindValue(':tabcd_c', $data['tabcd'], PDO::PARAM_INT);
$lfirst->bindValue(':lcd_a', $data['lcd'], PDO::PARAM_INT);
$lfirst->bindValue(':lcd_b', $data['lcd'], PDO::PARAM_INT);
$lnext->bindValue(':cid_a', $data['cid'], PDO::PARAM_INT);
$lnext->bindValue(':cid_b', $data['cid'], PDO::PARAM_INT);
$lnext->bindValue(':tabcd_a', $data['tabcd'], PDO::PARAM_INT);
$lnext->bindValue(':tabcd_b', $data['tabcd'], PDO::PARAM_INT);
$lfirst->execute();
while($segment = $lfirst->fetch(PDO::FETCH_ASSOC))
{
$segments = array();
for(;;)
{
$segment = find_names($segment);
$segments[] = $segment;
$lnext->bindValue(':lcd_a', $segment['pos_off_lcd'], PDO::PARAM_INT);
$lnext->bindValue(':lcd_b', $segment['pos_off_lcd'], PDO::PARAM_INT);
$lnext->execute();
if(!($segment = $lnext->fetch(PDO::FETCH_ASSOC)))
break;
}
}
}
return $segments;
}
function find_area_points($data)
{
global $pdo;
static $stmt = null;
if($stmt === null)
$stmt = $pdo->prepare("SELECT * FROM points WHERE cid = :cid AND tabcd = :tabcd AND (pol_lcd = :pol_lcd OR oth_lcd = :oth_lcd) ORDER BY junctionnumber, rnid, n1id, n2id ASC");
$stmt->bindValue(':cid', $data['cid'], PDO::PARAM_INT);
$stmt->bindValue(':tabcd', $data['tabcd'], PDO::PARAM_INT);
$stmt->bindValue(':pol_lcd', $data['lcd'], PDO::PARAM_INT);
$stmt->bindValue(':oth_lcd', $data['lcd'], PDO::PARAM_INT);
$stmt->execute();
if($result = $stmt->fetchAll(PDO::FETCH_ASSOC))
return array_map("find_names", $result);
else
return array();
}
function find_area_segments($data)
{
global $pdo;
static $stmt = null;
if($stmt === null)
$stmt = $pdo->prepare("SELECT * FROM segments WHERE cid = :cid AND tabcd = :tabcd AND pol_lcd = :pol_lcd ORDER BY roadnumber, rnid, n1id, n2id ASC");
$stmt->bindValue(':cid', $data['cid'], PDO::PARAM_INT);
$stmt->bindValue(':tabcd', $data['tabcd'], PDO::PARAM_INT);
$stmt->bindValue(':pol_lcd', $data['lcd'], PDO::PARAM_INT);
$stmt->execute();
if($result = $stmt->fetchAll(PDO::FETCH_ASSOC))
return array_map("find_names", $result);
else
return array();
}
function find_area_roads($data)
{
global $pdo;
static $stmt = null;
if($stmt === null)
$stmt = $pdo->prepare("SELECT * FROM roads WHERE cid = :cid AND tabcd = :tabcd AND pol_lcd = :pol_lcd ORDER BY roadnumber, rnid, n1id, n2id ASC");
$stmt->bindValue(':cid', $data['cid'], PDO::PARAM_INT);
$stmt->bindValue(':tabcd', $data['tabcd'], PDO::PARAM_INT);
$stmt->bindValue(':pol_lcd', $data['lcd'], PDO::PARAM_INT);
$stmt->execute();
if($result = $stmt->fetchAll(PDO::FETCH_ASSOC))
return array_map("find_names", $result);
else
return array();
}
function find_area_admins($data)
{
global $pdo;
static $stmt = null;
if($stmt === null)
$stmt = $pdo->prepare("SELECT * FROM administrativearea WHERE cid = :cid AND tabcd = :tabcd AND pol_lcd = :pol_lcd ORDER BY nid ASC");
$stmt->bindValue(':cid', $data['cid'], PDO::PARAM_INT);
$stmt->bindValue(':tabcd', $data['tabcd'], PDO::PARAM_INT);
$stmt->bindValue(':pol_lcd', $data['lcd'], PDO::PARAM_INT);
$stmt->execute();
if($result = $stmt->fetchAll(PDO::FETCH_ASSOC))
return array_map("find_names", $result);
else
return array();
}
function find_area_others($data)
{
global $pdo;
static $stmt = null;
if($stmt === null)
$stmt = $pdo->prepare("SELECT * FROM otherareas WHERE cid = :cid AND tabcd = :tabcd AND pol_lcd = :pol_lcd ORDER BY nid ASC");
$stmt->bindValue(':cid', $data['cid'], PDO::PARAM_INT);
$stmt->bindValue(':tabcd', $data['tabcd'], PDO::PARAM_INT);
$stmt->bindValue(':pol_lcd', $data['lcd'], PDO::PARAM_INT);
$stmt->execute();
if($result = $stmt->fetchAll(PDO::FETCH_ASSOC))
return array_map("find_names", $result);
else
return array();
}
function find_country($cid)
{
global $pdo;
static $stmt = null;
if($stmt === null)
$stmt = $pdo->prepare("SELECT * FROM countries WHERE cid = :cid");
$stmt->bindValue(':cid', $cid, PDO::PARAM_INT);
$stmt->execute();
if(!($data = $stmt->fetch(PDO::FETCH_ASSOC)))
return false;
return $data;
}
?>