与IBM i的远程PHP DB2连接中未使用库列表
我已经通过PHP从本地Windows PC成功连接到远程IBM i DB2数据库(AS400)。我将IBM Data Server Client与PHP中的 db2 _ *
函数结合使用。我遇到的问题是,尽管我的库列表设置正确,但没有将其用于不合格的表名。而是使用当前用户名作为库。但是,当我限定表名时,所有内容都像一个符咒。
I've successfully connected to a remote IBM i DB2 database (AS400) from my local Windows PC via PHP. I'm using the IBM Data Server Client in conjunction with the db2_*
functions in PHP. The problem I'm having is that despite my library list being set properly, it is not being used for unqualified table names. Instead it uses the current user name as the library. However, when I qualify the table names everything works like a charm.
通过查询 QSYS2.LIBRARY_LIST_INFO
,创建连接时,我已经确认我的库列表实际上正在更改。
I've confirmed that my library list is actually changing when I create the connection by querying QSYS2.LIBRARY_LIST_INFO
.
$database = '<database name>';
$user = '<user name>';
$password = '<password';
$port = <port>;
$options['i5_naming'] = DB2_I5_NAMING_ON;
$options['autocommit'] = DB2_AUTOCOMMIT_OFF;
$options['i5_libl'] = 'MYLIB YOURLIB ANYLIB';
$conn = db2_connect($database, $user, $password, $options);
if ($conn) {
echo "Connection succeeded."; //It succeeds
}
else {
echo db2_conn_error()." | ".db2_conn_errormsg()."<br />";
echo "Connection failed.";
}
$sql = "SELECT * FROM QSYS2.LIBRARY_LIST_INFO";
//Works and proves my library list reflects
//what I passed in when creating the connection.
//$sql = "SELECT * FROM LIBRARY_LIST_INFO";
//Generates: "42S02 : [IBM][CLI Driver][AS] SQL0204N "<user name>.LIBRARY_LIST_INFO" is an undefined name. SQLSTATE=42704 SQLCODE=-204"
//where <user name> is the username used to connect to the DB.
//It should be using the library list specified when creating the connection though.
//This holds true for any table from any library including those specified
//when creating the connection (which includes QSYS2).
$stmt = db2_prepare($conn, $sql);
$result = db2_execute($stmt);
if($result){
while($row = db2_fetch_assoc($stmt)){
echo "<pre>";
var_dump($row); //In addition to entries for QSYS, QSYS2, QUSRSYS and QHLPSYS I get entries for MYLIB, YOURLIB and ANYLIB.
echo "</pre>";
}
}else{
echo "failed<br />";
echo db2_stmt_error()." : ".db2_stmt_errormsg()."<br />";
}
有人在连接到远程DB2服务器时启用i5_naming时遇到此问题?我不太确定为什么不使用我的库列表,因为PHP手册指出使用作业的库列表可以解决不合格的文件。启用时。 http://php.net/manual/zh/function.db2-connect。 php
Has anyone ever run into this while enabling i5_naming when connecting to a remote DB2 server? I'm not really sure why it wouldn't be using my library list as the PHP manual states "Unqualified files are resolved using the library list for the job." when enabled. http://php.net/manual/en/function.db2-connect.php
在与IBM打开PMR之后,我终于解决了这个问题。我要做的就是应用最新的DB2 Connect个人版修订包。
I finally solved this after opening a PMR with IBM. All I had to do was apply the latest Fix Pack for DB2 Connect Personal Edition.
建议的DB2 Connect修订包:
Suggested Fix Packs for DB2 Connect:
http:// www-01。 ibm.com/support/docview.wss?rs=71&uid=swg21321001
基本上,我在2013年之前发布了DB2 Connect版本。 IBM在2013年通过添加 i5_naming
选项添加了两层支持。因此,我的DB2 Connect安装程序实际上忽略了我传递的选项。因此,这说明了为什么其他选项仍然存在。在数据库方面,由于它没有收到 i5_naming
的值,因此仍保留为默认值。
Basically the DB2 Connect version I had was released prior to 2013. It was in 2013 IBM added two tier support by adding the i5_naming
option. So my DB2 Connect setup was effectively ignoring the option I was passing. So that explains why the other options still went through. On the DB side, since it didn't receive a value for i5_naming
- it remained as the default.