如何使用PHP连接到as400

2024-01-04

我正在尝试使用以下代码将我的 AS400 与 V5R3 和 PHP 连接:

<?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][System i Access 的 ODBC 控制程序][DB2 per i5/OS]SQL0104 - 令牌无效。令牌有效: = != >= � �= IN IS NOT LIKE BETWEEN., SQLExecDirect 中的 SQL 状态 37000 F:\xampp\htdocs\php-as400\php- as400.php 第 25 行 SQL 错误

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

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 https://bugs.php.net/bug.php?id=47133),但我不知道如何解决。


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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用PHP连接到as400 的相关文章