How to connect to as400 from PHP

I am trying to connect my AS400 to V5R3 using PHP with this code:

$server="Driver={Client Access ODBC Driver (32-bit)};;
Uid=user;Pwd=password;"; #the name of the iSeries
$user="user"; #a valid username that will connect to the DB
$pass="password"; #a password for the username

$conn=odbc_connect($server,$user,$pass); #you may have to remove quotes

#Check Connection
if ($conn == false) {
echo "Not able to connect to database...<br>";

#Query the Database into a result set - 
$result=odbc_exec($conn,"SELECT * FROM LIBRARY.V5TDOC0L WHERE T§DTDO = 20120319");

if (!$result)
  {exit("Error in SQL");}
echo "<table><tr>";
echo "<th>T§NDOC</th>";
echo "<th>T§DTDO</th></tr>";
while (odbc_fetch_row($result))
  echo "<tr><td>$ndoc</td>";
  echo "<td>$dtdo</td></tr>";
echo "</table>";

#close the connection


I got this error:

Warning: odbc_exec () [function.odbc-exec]: SQL error: [IBM] [Programma di controllo ODBC di System i Access] [DB2 per i5 / OS] SQL0104 - The token is invalid. Current token: <> = <<<= <! >! => = <> = IN DO NOT LIKE BETWEEN., SQL 37000 status in SQLExecDirect at F: \ xampp \ htdocs \ php-as400 \ php-as400.php on line 25 Error in SQL

Removing from SELECT statement WHERE T§DTDO = 20120319

, I run it and list the items I want with a warning.

Fatal error: Maximum execution time of 30 seconds exceeded in F:\xampp\htdocs\php-as400\php-as400.php on line 30
C008931 19941102
P005027 19950214
P005031 19950320
P005055 19950612
P005062 19950904
P005065 19950920
P005082 19951218
P005157 19970102
P005186 19970428
P005187 19970429
P005190 19970520
I009353 19970721
P005257 19980217 


Line 30:

while (odbc_fetch_row($result))


I believe the problem is in the nature of § as I found on the internet ( ), but I don't know how to solve it.


source to share

3 answers

I've never seen a character used before in a column name. This could be a code page conversion issue. Ask your IBM administrator to check the column name; it can be T @DTDO, T # DTDO, or T $ DTDO - whatever you can actually type. If not, try enclosing the column name in double quotes: ... where "T§DTDO" = 20120319 ... If that doesn't work, have your DB2 administrator create a view with column names that have no special characters in them.



Try using quotes:

$result=odbc_exec($conn,'SELECT * FROM LIBRARY.V5TDOC0L WHERE "T§DTDO" = 20120319');




The character § and £ are the "Italian equivalent" to @ and #.

In the Italian CCSID (e.g. 280), you will see (and use) the V5TDOC0L fields like this: T§TDOC, T§NDOC. In another CCSID (e.g. 37), you will see T @TDOC and T @NDOC (for the same file!).

I don't know which ccsid the job serving the PHP page will use. This may depend on the system default.




All Articles