如何使用PHP连接到as400 [英] howto connect to as400 with PHP

查看:167
本文介绍了如何使用PHP连接到as400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此代码将AS400和V5R3与PHP连接起来:

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);
?>

我收到此错误:

警告:odbc_exec()[function.odbc-exec]:SQL错误:[IBM] [系统访问控制ODBC的程序] [基于i5/OS的DB2] SQL0104-令牌-无效.令牌有效:< > =<>< =!< !>!=> = < >> =不一样,第25行的F:\ xampp \ htdocs \ php-as400 \ php-as400.php中的SQLExecDirect中的SQL状态37000 SQL错误

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

从语句SELECT中删除WHERE T§DTDO = 20120319,我让它运行并列出我想要的元素,并给出警告.

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 

第30行是:

while (odbc_fetch_row($result))

我认为问题出在我在互联网上找到的字符§( https://bugs.php.net/bug.php?id=47133 ),但我不知道如何解决.

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.

推荐答案

我以前从未见过列名中使用的字符§.这可能是代码页转换问题.询问IBM i管理员以验证列名称;请参阅IBM i管理员.它实际上可能是T @ DTDO,T#DTDO或T $ DTDO-您可以实际键入.如果失败,请尝试将列名括在双引号中:...其中T§DTDO" = 20120319 ...如果不起作用,请让DB2管理员创建一个视图,其中的列名中不包含特殊字符他们.

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.

这篇关于如何使用PHP连接到as400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆