1
1
<?php
2
2
function dbQuery ($ query , $ show_errors =true , $ all_results =true , $ show_output =true ) {
3
+ putenv ("INFORMIXDIR=/opt/IBM/informix " );
4
+ putenv ("INFORMIXSERVER=ol_informix1170 " );
5
+ putenv ("ONCONFIG=onconfig.ol_informix1170 " );
6
+ putenv ("INFORMIXSQLHOSTS=/opt/IBM/informix/etc/sqlhosts.ol_informix1170 " );
7
+ putenv ("LD_LIBRARY_PATH=/opt/IBM/informix/lib:/opt/IBM/informix/lib/cli:/opt/IBM/informix/lib/esql:/opt/IBM/informix/lib/tools " );
8
+ putenv ("ODBCINI=/etc/odbc.ini " );
9
+
3
10
if ($ show_errors )
4
11
error_reporting (E_ALL );
5
12
else
6
13
error_reporting (E_PARSE );
7
14
8
15
// Connect to the Informix database management system
9
16
// NOTE: it is installed on localhost
10
- $ link = ifx_pconnect ("online_root@localhost " , "" , "" );
11
- if (!$ link ) {
12
- die (ifx_error ());
17
+ try {
18
+ // Call the PDO class.
19
+ $ link = new PDO ('informix:DSN=inf ' );
20
+ }
21
+ catch (PDOException $ e ) {
22
+ // If something goes wrong, PDO throws an exception with a nice error message.
23
+ echo $ e ->getMessage ();
13
24
}
14
25
15
26
// Print results in HTML
@@ -19,12 +30,11 @@ function dbQuery($query, $show_errors=true, $all_results=true, $show_output=true
19
30
//print "<b>SQL query:</b> " . $query . "<br>\n";
20
31
21
32
// Perform SQL injection affected query
22
- $ result = ifx_query ($ query , $ link );
33
+ $ stmt = $ link ->query ($ query );
34
+ $ stmt ->setFetchMode (PDO ::FETCH_COLUMN );
23
35
24
- if (!$ result ) {
25
- if ($ show_errors )
26
- print "<b>SQL error:</b> " . ifx_error () . "<br> \n" ;
27
- exit (1 );
36
+ if (!$ stmt ) {
37
+ exit (1 );
28
38
}
29
39
30
40
if (!$ show_output )
@@ -33,12 +43,12 @@ function dbQuery($query, $show_errors=true, $all_results=true, $show_output=true
33
43
print "<b>SQL results:</b> \n" ;
34
44
print "<table border= \"1 \"> \n" ;
35
45
36
- while ( $ line = ifx_fetch_row ( $ result )) {
46
+ while ( $ row = $ stmt -> fetch ( )) {
37
47
print "<tr> " ;
38
- foreach ( $ line as $ col_value ) {
39
- print "<td> " . $ col_value . "</td> " ;
40
- }
41
- print "</tr> \n" ;
48
+ echo " <td> " . $ row [ 0 ] . " </td> " ;
49
+ echo "<td> " . $ row [ 1 ] . "</td> " ;
50
+ echo " <td> " . $ row [ 2 ] . " </td> " ;
51
+ echo "</tr> \n" ;
42
52
if (!$ all_results )
43
53
break ;
44
54
}
0 commit comments