Skip to content

Commit 63e3445

Browse files
committed
fixed Informix lib to use PDO
1 parent 25b8d31 commit 63e3445

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

libs/informix.inc.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
<?php
22
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+
310
if ($show_errors)
411
error_reporting(E_ALL);
512
else
613
error_reporting(E_PARSE);
714

815
// Connect to the Informix database management system
916
// 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();
1324
}
1425

1526
// Print results in HTML
@@ -19,12 +30,11 @@ function dbQuery($query, $show_errors=true, $all_results=true, $show_output=true
1930
//print "<b>SQL query:</b> " . $query . "<br>\n";
2031

2132
// Perform SQL injection affected query
22-
$result = ifx_query($query, $link);
33+
$stmt = $link->query($query);
34+
$stmt->setFetchMode(PDO::FETCH_COLUMN);
2335

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);
2838
}
2939

3040
if (!$show_output)
@@ -33,12 +43,12 @@ function dbQuery($query, $show_errors=true, $all_results=true, $show_output=true
3343
print "<b>SQL results:</b>\n";
3444
print "<table border=\"1\">\n";
3545

36-
while ($line = ifx_fetch_row($result)) {
46+
while($row = $stmt->fetch()) {
3747
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";
4252
if (!$all_results)
4353
break;
4454
}

0 commit comments

Comments
 (0)