farleyknight-ionize 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/README.rdoc +59 -0
  2. data/Rakefile +5 -0
  3. data/bin/ionize +47 -0
  4. data/lib/ionize.rb +75 -0
  5. data/lib/ionize/environment.rb +56 -0
  6. data/lib/ionize/environment/application.rb +58 -0
  7. data/lib/ionize/environment/php_array.rb +95 -0
  8. data/lib/ionize/parser.rb +272 -0
  9. data/lib/ionize/tokenizer.rb +544 -0
  10. data/lib/ionize/translate.rb +34 -0
  11. data/lib/ionize/translate/composite_string_statements.rb +79 -0
  12. data/lib/ionize/translate/debug.rb +16 -0
  13. data/lib/ionize/translate/ext.rb +47 -0
  14. data/lib/ionize/translate/function_args.rb +132 -0
  15. data/lib/ionize/translate/if_statements.rb +42 -0
  16. data/lib/ionize/translate/multiple_statements.rb +22 -0
  17. data/lib/ionize/translate/php_to_ruby.rb +40 -0
  18. data/lib/ionize/translate/rails_for_php.rb +191 -0
  19. data/lib/ionize/translate/rewritable.rb +133 -0
  20. data/lib/ionize/translate/rewrites.rb +51 -0
  21. data/lib/ionize/translate/statements.rb +622 -0
  22. data/lib/ionize/translate/switch_case_statements.rb +52 -0
  23. data/lib/ionize/translate/term_statements.rb +76 -0
  24. data/lib/ionize/translate/translator.rb +52 -0
  25. data/lib/ionize/version.rb +9 -0
  26. data/spec/fixtures/array_lookup.php +10 -0
  27. data/spec/fixtures/boolean_operators.php +5 -0
  28. data/spec/fixtures/boolean_operators.rb +6 -0
  29. data/spec/fixtures/class_def.php +34 -0
  30. data/spec/fixtures/class_def.rb +34 -0
  31. data/spec/fixtures/dangling_else.php +8 -0
  32. data/spec/fixtures/dangling_else.rb +12 -0
  33. data/spec/fixtures/drupal_1.php +663 -0
  34. data/spec/fixtures/drupal_2.php +1152 -0
  35. data/spec/fixtures/empty_string.php +12 -0
  36. data/spec/fixtures/for_loop.php +17 -0
  37. data/spec/fixtures/for_loop2.php +13 -0
  38. data/spec/fixtures/for_loop3.php +16 -0
  39. data/spec/fixtures/for_loop3.rb +17 -0
  40. data/spec/fixtures/for_loop4.php +5 -0
  41. data/spec/fixtures/for_loop4.rb +6 -0
  42. data/spec/fixtures/foreach.php +9 -0
  43. data/spec/fixtures/foreach2.php +8 -0
  44. data/spec/fixtures/foreach3.php +7 -0
  45. data/spec/fixtures/foreach3.rb +7 -0
  46. data/spec/fixtures/fun_def.php +9 -0
  47. data/spec/fixtures/fun_def2.php +30 -0
  48. data/spec/fixtures/fun_def2.rb +30 -0
  49. data/spec/fixtures/fun_def3.php +33 -0
  50. data/spec/fixtures/fun_def4.php +43 -0
  51. data/spec/fixtures/fun_def4.rb +37 -0
  52. data/spec/fixtures/fun_def5.php +36 -0
  53. data/spec/fixtures/fun_with_if.php +6 -0
  54. data/spec/fixtures/fun_with_if.rb +6 -0
  55. data/spec/fixtures/fun_with_ifs.php +12 -0
  56. data/spec/fixtures/fun_with_ifs.rb +14 -0
  57. data/spec/fixtures/hello_world.php +6 -0
  58. data/spec/fixtures/heredoc.php +6 -0
  59. data/spec/fixtures/heredoc.rb +5 -0
  60. data/spec/fixtures/if.php +6 -0
  61. data/spec/fixtures/if.rb +7 -0
  62. data/spec/fixtures/if_boolean.php +5 -0
  63. data/spec/fixtures/if_boolean.rb +5 -0
  64. data/spec/fixtures/if_else.php +11 -0
  65. data/spec/fixtures/if_else1.php +17 -0
  66. data/spec/fixtures/if_else2.php +8 -0
  67. data/spec/fixtures/if_else3.php +15 -0
  68. data/spec/fixtures/if_else_nested.php +14 -0
  69. data/spec/fixtures/if_else_nested.rb +15 -0
  70. data/spec/fixtures/if_else_series.php +12 -0
  71. data/spec/fixtures/if_else_series.rb +12 -0
  72. data/spec/fixtures/if_not.php +5 -0
  73. data/spec/fixtures/if_not.rb +5 -0
  74. data/spec/fixtures/if_with_brackets.php +7 -0
  75. data/spec/fixtures/if_with_brackets.rb +7 -0
  76. data/spec/fixtures/long_if_else.php +10 -0
  77. data/spec/fixtures/long_if_else.rb +9 -0
  78. data/spec/fixtures/oo.php +16 -0
  79. data/spec/fixtures/php_nuke/sql_layer.php +527 -0
  80. data/spec/fixtures/postop.php +3 -0
  81. data/spec/fixtures/preop.php +7 -0
  82. data/spec/fixtures/simple_fun_def.php +4 -0
  83. data/spec/fixtures/switch_case.php +13 -0
  84. data/spec/fixtures/switch_case.rb +14 -0
  85. data/spec/fixtures/switch_case2.php +25 -0
  86. data/spec/fixtures/switch_case3.php +40 -0
  87. data/spec/fixtures/switch_case3.rb +42 -0
  88. data/spec/fixtures/switch_case4.php +56 -0
  89. data/spec/fixtures/switch_case5.php +71 -0
  90. data/spec/fixtures/switch_case_with_rescue_nil.php +43 -0
  91. data/spec/fixtures/switch_case_with_rescue_nil.rb +35 -0
  92. data/spec/fixtures/tertiary.php +3 -0
  93. data/spec/helper.rb +17 -0
  94. data/spec/php_environment_spec.rb +83 -0
  95. data/spec/php_parser_spec.rb +121 -0
  96. data/spec/php_translator_spec.rb +358 -0
  97. data/spec/rails_for_php_spec.rb +303 -0
  98. metadata +191 -0
@@ -0,0 +1,5 @@
1
+
2
+ $attributes = array();
3
+ if (array_key_exists('not null', $attributes) and $attributes['not null']) {
4
+ $not_null = 'NOT NULL';
5
+ }
@@ -0,0 +1,5 @@
1
+
2
+ attributes = array()
3
+ if array_key_exists('not null', attributes) and attributes['not null']
4
+ not_null = 'NOT NULL'
5
+ end
@@ -0,0 +1,11 @@
1
+
2
+ $check = "test";
3
+ $check .= $filename;
4
+
5
+ if ($test == $check) {
6
+ print("You have already voted");
7
+ } else {
8
+ $rated = "test";
9
+ $rated .= $filename;
10
+ print("I recorded your vote");
11
+ }
@@ -0,0 +1,17 @@
1
+
2
+
3
+
4
+ $check = "test";
5
+ $check .= $filename;
6
+ if ($test == $check)
7
+ {
8
+ while ($another == "thing") {
9
+ print("You have already voted");
10
+ }
11
+ }
12
+ else
13
+ {
14
+ $rated = "test";
15
+ $rated .= $filename;
16
+ print("I recorded your vote");
17
+ }
@@ -0,0 +1,8 @@
1
+
2
+
3
+ if ($type == 'module' && isset($modules[$name])) {
4
+ $file = $modules[$name];
5
+ } else if ($type == 'theme' && isset($themes[$name])) {
6
+ $file = $themes[$name];
7
+ }
8
+
@@ -0,0 +1,15 @@
1
+
2
+
3
+ if ($type == 'module' && isset($modules[$name])) {
4
+ $file = $modules[$name];
5
+ } else if ($type == 'theme' && isset($themes[$name])) {
6
+ $file = $themes[$name];
7
+ } else if ($type == 'theme' && isset($themes[$name])) {
8
+ $file = $themes[$name];
9
+ } else if ($type == 'theme' && isset($themes[$name])) {
10
+ $file = $themes[$name];
11
+ } else if ($type == 'theme' && isset($themes[$name])) {
12
+ $file = $themes[$name];
13
+ }
14
+
15
+
@@ -0,0 +1,14 @@
1
+
2
+ $attributes = array();
3
+
4
+ if (array_key_exists('default', $attributes)) {
5
+ if (is_null($attributes['default'])) {
6
+ $default_val = 'NULL';
7
+ $default = 'default NULL';
8
+ } elseif ($attributes['default'] === FALSE) {
9
+ $default = '';
10
+ } else {
11
+ $default_val = "$attributes[default]";
12
+ $default = "default $attributes[default]";
13
+ }
14
+ }
@@ -0,0 +1,15 @@
1
+
2
+
3
+ attributes = array()
4
+
5
+ if (array_key_exists('default', attributes))
6
+ if is_null(attributes['default'])
7
+ default_val = 'NULL'
8
+ default = 'default NULL'
9
+ elsif attributes['default'] === false
10
+ default = ''
11
+ else
12
+ default_val = "#{attributes['default']}"
13
+ default = "default #{attributes['default']}"
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+
2
+ $something = "value";
3
+
4
+ if ($something == $something)
5
+ print "value";
6
+ elseif ($something != $something)
7
+ print "not value";
8
+ else if ($something == "value")
9
+ print "value";
10
+ else
11
+ print "else";
12
+
@@ -0,0 +1,12 @@
1
+
2
+ something = "value"
3
+
4
+ if something == something
5
+ print "value"
6
+ elsif something != something
7
+ print "not value"
8
+ elsif something == "value"
9
+ print "value"
10
+ else
11
+ print "else"
12
+ end
@@ -0,0 +1,5 @@
1
+
2
+ $var = array();
3
+ if (!empty($var)) {
4
+ print "!empty";
5
+ }
@@ -0,0 +1,5 @@
1
+
2
+ var = array()
3
+ if !empty(var)
4
+ print "!empty"
5
+ end
@@ -0,0 +1,7 @@
1
+
2
+
3
+ $something = "value";
4
+
5
+ if ($something == "value") {
6
+ print "value";
7
+ }
@@ -0,0 +1,7 @@
1
+
2
+
3
+ something = "value"
4
+
5
+ if something == "value"
6
+ print "value"
7
+ end
@@ -0,0 +1,10 @@
1
+
2
+
3
+ $attributes = array();
4
+ if ($attributes == "something") {
5
+ print 'okay';
6
+ print 'yeah';
7
+ } else {
8
+ print "wtf";
9
+ print "okay";
10
+ }
@@ -0,0 +1,9 @@
1
+
2
+ attributes = array()
3
+ if attributes == "something"
4
+ print "okay"
5
+ print "yeah"
6
+ else
7
+ print "wtf"
8
+ print "okay"
9
+ end
@@ -0,0 +1,16 @@
1
+
2
+
3
+ function update_fix_compatibility() {
4
+ $ret = array();
5
+ $incompatible = array();
6
+ $query = db_query("SELECT name, type, status FROM {system} WHERE status = 1 AND type IN ('module','theme')");
7
+ while ($result = db_fetch_object($query)) {
8
+ if (update_check_incompatibility($result->name, $result->type)) {
9
+ $incompatible[] = $result->name;
10
+ }
11
+ }
12
+ if (!empty($incompatible)) {
13
+ $ret[] = update_sql("UPDATE {system} SET status = 0 WHERE name IN ('". implode("','", $incompatible) ."')");
14
+ }
15
+ return $ret;
16
+ }
@@ -0,0 +1,527 @@
1
+ <?php
2
+
3
+ /************************************************************************/
4
+ /* PHP-NUKE: Web Portal System */
5
+ /* =========================== */
6
+ /* */
7
+ /* Copyright (c) 2002 by Francisco Burzi */
8
+ /* http://phpnuke.org */
9
+ /* */
10
+ /* postgres fix by Ruben Campos - Oscar Silla */
11
+ /* */
12
+ /* This program is free software. You can redistribute it and/or modify */
13
+ /* it under the terms of the GNU General Public License as published by */
14
+ /* the Free Software Foundation; either version 2 of the License. */
15
+ /************************************************************************/
16
+
17
+ if (stristr(htmlentities($_SERVER['PHP_SELF']), "sql_layer.php")) {
18
+ Header("Location: ../index.php");
19
+ die();
20
+ }
21
+
22
+ /* $dbtype = "MySQL"; */
23
+ /* $dbtype = "mSQL"; */
24
+ /* $dbtype = "postgres"; */
25
+ /* $dbtype = "postgres_local";// When postmaster start without "-i" option. */
26
+ /* $dbtype = "ODBC"; */
27
+ /* $dbtype = "ODBC_Adabas"; */
28
+ /* $dbtype = "Interbase"; */
29
+ /* $dbtype = "Sybase"; */
30
+
31
+ /*
32
+ * sql_connect($host, $user, $password, $db)
33
+ * returns the connection ID
34
+ */
35
+
36
+
37
+ class ResultSet {
38
+ var $result;
39
+ var $total_rows;
40
+ var $fetched_rows;
41
+
42
+ function set_result( $res ) {
43
+ $this->result = $res;
44
+ }
45
+
46
+ function get_result() {
47
+ return $this->result;
48
+ }
49
+
50
+ function set_total_rows( $rows ) {
51
+ $this->total_rows = $rows;
52
+ }
53
+
54
+ function get_total_rows() {
55
+ return $this->total_rows;
56
+ }
57
+
58
+ function set_fetched_rows( $rows ) {
59
+ $this->fetched_rows = $rows;
60
+ }
61
+
62
+ function get_fetched_rows() {
63
+ return $this->fetched_rows;
64
+ }
65
+
66
+ function increment_fetched_rows() {
67
+ $this->fetched_rows = $this->fetched_rows + 1;
68
+ }
69
+ }
70
+
71
+
72
+
73
+ function sql_connect($host, $user, $password, $db)
74
+ {
75
+ global $dbtype;
76
+ switch ($dbtype) {
77
+
78
+ case "MySQL":
79
+ $dbi=@mysql_connect($host, $user, $password);
80
+ mysql_select_db($db);
81
+ return $dbi;
82
+ break;;
83
+
84
+ case "mSQL":
85
+ $dbi=msql_connect($host);
86
+ msql_select_db($db);
87
+ return $dbi;
88
+ break;;
89
+
90
+
91
+ case "postgres":
92
+ $dbi=@pg_connect("host=$host user=$user password=$password port=5432 dbname=$db");
93
+ return $dbi;
94
+ break;;
95
+
96
+ case "postgres_local":
97
+ $dbi=@pg_connect("user=$user password=$password dbname=$db");
98
+ return $dbi;
99
+ break;;
100
+
101
+ case "ODBC":
102
+ $dbi=@odbc_connect($db,$user,$password);
103
+ return $dbi;
104
+ break;;
105
+
106
+ case "ODBC_Adabas":
107
+ $dbi=@odbc_connect($host.":".$db,$user,$password);
108
+ return $dbi;
109
+ break;;
110
+
111
+ case "Interbase":
112
+ $dbi=@ibase_connect($host.":".$db,$user,$password);
113
+ return $dbi;
114
+ break;;
115
+
116
+ case "Sybase":
117
+ $dbi=@sybase_connect($host, $user, $password);
118
+ sybase_select_db($db,$dbi);
119
+ return $dbi;
120
+ break;;
121
+
122
+ default:
123
+ break;;
124
+ }
125
+
126
+ }
127
+
128
+ function sql_logout($id)
129
+ {
130
+ global $dbtype;
131
+ switch ($dbtype) {
132
+
133
+ case "MySQL":
134
+ $dbi=@mysql_close($id);
135
+ return $dbi;
136
+ break;;
137
+
138
+ case "mSQL":
139
+ $dbi=@msql_close($id);
140
+ return $dbi;
141
+ break;;
142
+
143
+ case "postgres":
144
+ case "postgres_local":
145
+ $dbi=@pg_close($id);
146
+ return $dbi;
147
+ break;;
148
+
149
+ case "ODBC":
150
+ case "ODBC_Adabas":
151
+ $dbi=@odbc_close($id);
152
+ return $dbi;
153
+ break;;
154
+
155
+ case "Interbase":
156
+ $dbi=@ibase_close($id);
157
+ return $dbi;
158
+ break;;
159
+
160
+ case "Sybase":
161
+ $dbi=@sybase_close($id);
162
+ return $dbi;
163
+ break;;
164
+
165
+ default:
166
+ break;;
167
+ }
168
+ }
169
+
170
+
171
+ /*
172
+ * sql_query($query, $id)
173
+ * executes an SQL statement, returns a result identifier
174
+ */
175
+
176
+ function sql_query($query, $id)
177
+ {
178
+ global $dbtype, $sql_debug;
179
+ $sql_debug = 0;
180
+
181
+ if($sql_debug) echo "SQL query: ".str_replace(",",", ",$query)."<BR>";
182
+
183
+ switch ($dbtype) {
184
+
185
+ case "MySQL":
186
+ $res=@mysql_query($query, $id);
187
+ return $res;
188
+ break;;
189
+
190
+ case "mSQL":
191
+ $res=@msql_query($query, $id);
192
+ return $res;
193
+ break;;
194
+
195
+ case "postgres":
196
+ case "postgres_local":
197
+ $res=pg_exec($id,$query);
198
+ $result_set = new ResultSet;
199
+ $result_set->set_result( $res );
200
+ $result_set->set_total_rows( sql_num_rows( $result_set ) );
201
+ $result_set->set_fetched_rows( 0 );
202
+ return $result_set;
203
+ break;;
204
+
205
+ case "ODBC":
206
+ case "ODBC_Adabas":
207
+ $res=@odbc_exec($id,$query);
208
+ return $res;
209
+ break;;
210
+
211
+ case "Interbase":
212
+ $res=@ibase_query($id,$query);
213
+ return $res;
214
+ break;;
215
+
216
+ case "Sybase":
217
+ $res=@sybase_query($query, $id);
218
+ return $res;
219
+ break;;
220
+
221
+ default:
222
+ break;;
223
+
224
+ }
225
+ }
226
+
227
+ /*
228
+ * sql_num_rows($res)
229
+ * given a result identifier, returns the number of affected rows
230
+ */
231
+
232
+ function sql_num_rows($res)
233
+ {
234
+ global $dbtype;
235
+ switch ($dbtype) {
236
+
237
+ case "MySQL":
238
+ $rows=mysql_num_rows($res);
239
+ return $rows;
240
+ break;;
241
+
242
+ case "mSQL":
243
+ $rows=msql_num_rows($res);
244
+ return $rows;
245
+ break;;
246
+
247
+ case "postgres":
248
+ case "postgres_local":
249
+ $rows=pg_numrows( $res->get_result() );
250
+ return $rows;
251
+ break;;
252
+
253
+ case "ODBC":
254
+ case "ODBC_Adabas":
255
+ $rows=odbc_num_rows($res);
256
+ return $rows;
257
+ break;;
258
+
259
+ case "Interbase":
260
+ echo "<BR>Error! PHP dosen't support ibase_numrows!<BR>";
261
+ return $rows;
262
+ break;;
263
+
264
+ case "Sybase":
265
+ $rows=sybase_num_rows($res);
266
+ return $rows;
267
+ break;;
268
+
269
+ default:
270
+ break;;
271
+ }
272
+ }
273
+
274
+ /*
275
+ * sql_fetch_row(&$res,$row)
276
+ * given a result identifier, returns an array with the resulting row
277
+ * Needs also a row number for compatibility with postgres
278
+ */
279
+
280
+ function sql_fetch_row(&$res, $nr=0)
281
+ {
282
+ global $dbtype;
283
+ switch ($dbtype) {
284
+
285
+ case "MySQL":
286
+ $row = mysql_fetch_row($res);
287
+ return $row;
288
+ break;;
289
+
290
+ case "mSQL":
291
+ $row = msql_fetch_row($res);
292
+ return $row;
293
+ break;;
294
+
295
+ case "postgres":
296
+ case "postgres_local":
297
+ if ( $res->get_total_rows() > $res->get_fetched_rows() ) {
298
+ $row = pg_fetch_row($res->get_result(), $res->get_fetched_rows() );
299
+ $res->increment_fetched_rows();
300
+ return $row;
301
+ } else {
302
+ return false;
303
+ }
304
+ break;;
305
+
306
+ case "ODBC":
307
+ case "ODBC_Adabas":
308
+ $row = array();
309
+ $cols = odbc_fetch_into($res, $nr, $row);
310
+ return $row;
311
+ break;;
312
+
313
+ case "Interbase":
314
+ $row = ibase_fetch_row($res);
315
+ return $row;
316
+ break;;
317
+
318
+ case "Sybase":
319
+ $row = sybase_fetch_row($res);
320
+ return $row;
321
+ break;;
322
+
323
+ default:
324
+ break;;
325
+ }
326
+ }
327
+
328
+ /*
329
+ * sql_fetch_array($res,$row)
330
+ * given a result identifier, returns an associative array
331
+ * with the resulting row using field names as keys.
332
+ * Needs also a row number for compatibility with postgres.
333
+ */
334
+
335
+ function sql_fetch_array(&$res, $nr=0)
336
+ {
337
+ global $dbtype;
338
+ switch ($dbtype)
339
+ {
340
+ case "MySQL":
341
+ $row = array();
342
+ $row = mysql_fetch_array($res);
343
+ return $row;
344
+ break;;
345
+
346
+ case "mSQL":
347
+ $row = array();
348
+ $row = msql_fetch_array($res);
349
+ return $row;
350
+ break;;
351
+
352
+ case "postgres":
353
+ case "postgres_local":
354
+ if( $res->get_total_rows() > $res->get_fetched_rows() ) {
355
+ $row = array();
356
+ $row = pg_fetch_array($res->get_result(), $res->get_fetched_rows() );
357
+ $res->increment_fetched_rows();
358
+ return $row;
359
+ } else {
360
+ return false;
361
+ }
362
+ break;;
363
+
364
+ /*
365
+ * ODBC doesn't have a native _fetch_array(), so we have to
366
+ * use a trick. Beware: this might cause HUGE loads!
367
+ */
368
+
369
+ case "ODBC":
370
+ $row = array();
371
+ $result = array();
372
+ $result = odbc_fetch_row($res, $nr);
373
+ $nf = odbc_num_fields($res); /* Field numbering starts at 1 */
374
+ for($count=1; $count < $nf+1; $count++) {
375
+ $field_name = odbc_field_name($res, $count);
376
+ $field_value = odbc_result($res, $field_name);
377
+ $row[$field_name] = $field_value;
378
+ }
379
+ return $row;
380
+ break;;
381
+
382
+ case "ODBC_Adabas":
383
+ $row = array();
384
+ $result = array();
385
+ $result = odbc_fetch_row($res, $nr);
386
+
387
+ $nf = count($result)+2; /* Field numbering starts at 1 */
388
+ for($count=1; $count < $nf; $count++) {
389
+ $field_name = odbc_field_name($res, $count);
390
+ $field_value = odbc_result($res, $field_name);
391
+ $row[$field_name] = $field_value;
392
+ }
393
+ return $row;
394
+ break;;
395
+
396
+ case "Interbase":
397
+ $orow=ibase_fetch_object($res);
398
+ $row=get_object_vars($orow);
399
+ return $row;
400
+ break;;
401
+
402
+ case "Sybase":
403
+ $row = sybase_fetch_array($res);
404
+ return $row;
405
+ break;;
406
+
407
+ }
408
+ }
409
+
410
+ function sql_fetch_object(&$res, $nr=0)
411
+ {
412
+ global $dbtype;
413
+ switch ($dbtype)
414
+ {
415
+ case "MySQL":
416
+ $row = mysql_fetch_object($res);
417
+ if($row) return $row;
418
+ else return false;
419
+ break;;
420
+
421
+ case "mSQL":
422
+ $row = msql_fetch_object($res);
423
+ if($row) return $row;
424
+ else return false;
425
+ break;;
426
+
427
+ case "postgres":
428
+ case "postgres_local":
429
+ if( $res->get_total_rows() > $res->get_fetched_rows() ) {
430
+ $row = pg_fetch_object( $res->get_result(), $res->get_fetched_rows() );
431
+ $res->increment_fetched_rows();
432
+ if($row) return $row;
433
+ else return false;
434
+ } else {
435
+ return false;
436
+ }
437
+ break;;
438
+
439
+ case "ODBC":
440
+ $result = odbc_fetch_row($res, $nr);
441
+ if(!$result) return false;
442
+ $nf = odbc_num_fields($res); /* Field numbering starts at 1 */
443
+ for($count=1; $count < $nf+1; $count++)
444
+ {
445
+ $field_name = odbc_field_name($res, $count);
446
+ $field_value = odbc_result($res, $field_name);
447
+ $row->$field_name = $field_value;
448
+ }
449
+ return $row;
450
+ break;;
451
+
452
+ case "ODBC_Adabas":
453
+ $result = odbc_fetch_row($res, $nr);
454
+ if(!$result) return false;
455
+
456
+ $nf = count($result)+2; /* Field numbering starts at 1 */
457
+ for($count=1; $count < $nf; $count++) {
458
+ $field_name = odbc_field_name($res, $count);
459
+ $field_value = odbc_result($res, $field_name);
460
+ $row->$field_name = $field_value;
461
+ }
462
+ return $row;
463
+ break;;
464
+
465
+ case "Interbase":
466
+ $orow = ibase_fetch_object($res);
467
+ if($orow)
468
+ {
469
+ $arow=get_object_vars($orow);
470
+ while(list($name,$key)=each($arow))
471
+ {
472
+ $name=strtolower($name);
473
+ $row->$name=$key;
474
+ }
475
+ return $row;
476
+ }else return false;
477
+ break;;
478
+
479
+ case "Sybase":
480
+ $row = sybase_fetch_object($res);
481
+ return $row;
482
+ break;;
483
+
484
+ }
485
+ }
486
+
487
+ /*** Function Free Result for function free the memory ***/
488
+ function sql_free_result($res) {
489
+ global $dbtype;
490
+ switch ($dbtype) {
491
+
492
+ case "MySQL":
493
+ $row = mysql_free_result($res);
494
+ return $row;
495
+ break;;
496
+
497
+ case "mSQL":
498
+ $row = msql_free_result($res);
499
+ return $row;
500
+ break;;
501
+
502
+
503
+ case "postgres":
504
+ case "postgres_local":
505
+ $rows=pg_FreeResult( $res->get_result() );
506
+ return $rows;
507
+ break;;
508
+
509
+ case "ODBC":
510
+ case "ODBC_Adabas":
511
+ $rows=odbc_free_result($res);
512
+ return $rows;
513
+ break;;
514
+
515
+ case "Interbase":
516
+ echo "<BR>Error! PHP dosen't support ibase_numrows!<BR>";
517
+ return $rows;
518
+ break;;
519
+
520
+ case "Sybase":
521
+ $rows=sybase_free_result($res);
522
+ return $rows;
523
+ break;;
524
+ }
525
+ }
526
+
527
+ ?>