howto connect to as400 with PHP

扶醉桌前 提交于 2019-12-23 17:16:51

问题


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

<?php
$server="Driver={Client Access ODBC Driver (32-bit)};System=xxx.xxx.xxx.xxx;
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))
  {
  $ndoc=odbc_result($result,2);
  $dtdo=odbc_result($result,3);
  echo "<tr><td>$ndoc</td>";
  echo "<td>$dtdo</td></tr>";
  }
echo "</table>";

#close the connection
odbc_close($conn);
?>

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 - Token � not valid. Token valid: < > = <> <= !< !> != >= �< �> �= IN IS NOT LIKE BETWEEN., SQL state 37000 in SQLExecDirect in F:\xampp\htdocs\php-as400\php-as400.php on line 25 Error in SQL

Removing from the statement SELECT the WHERE T§DTDO = 20120319, I have it running and listing the elements 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
T§NDOC  T§DTDO
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 is :

while (odbc_fetch_row($result))

I believe the problem is the character § as I found looking in internet (https://bugs.php.net/bug.php?id=47133), but I don't know how to solve it.


回答1:


I have never seen the character § used in a column name before. This might be a code page conversion issue. Ask the IBM i admin to verify the column name; it might really be T@DTDO, T#DTDO or T$DTDO - something you can actually type. Failing that, try enclosing the column name in double quotes: ...where "T§DTDO"=20120319... If that does not work, have the DB2 admin create a view with column names that don't have special characters in them.




回答2:


Try with the quotes:

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



回答3:


Character § and £ are the "italian-equivalent" of @ and #.

In italian CCSID (e.g. 280) you'll see (and use) the fields of V5TDOC0L in this way: T§TDOC, T§NDOC. In other CCSID (e.g. 37) you'll see T@TDOC and T@NDOC (for the same file!).

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

Try with "SELECT * FROM LIBRARY.V5TDOC0L WHERE T@DTDO = 20120319"



来源:https://stackoverflow.com/questions/9790944/howto-connect-to-as400-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!