odbc_prepare给出致命错误:允许的内存大小用尽 [英] odbc_prepare gives Fatal error: Allowed memory size exhausted

查看:121
本文介绍了odbc_prepare给出致命错误:允许的内存大小用尽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Debian服务器(64位),我想通过PHP将其连接到AS400的数据库.我已经安装了Linux和unixodbc的IBM i Access.我遵循了本教程:

I have a Debian server (64 bits) and I want to connect it to a AS400's database through PHP. I have installed the IBM i Access for Linux and unixodbc. I have followed this tutorial: https://www.albertopicado.es/conexion-odbc-con-base-de-datos-db2-en-un-servidor-ibm-iseries/ although it's in spanish you can see the proccess I have followed. The thing is that I can make a simple connection like:

$server= 'DRIVER={DRIVER_NAME};DATABASE=DATABASENAME;SYSTEM=IP;HOSTNAME=IP;PORT=NUMBER_OF_THE_PORT;PROTOCOL=TCPIP;';
$as400= odbc_connect($server, "username", "password");
$as400 ? echo "ok" : echo "ko";

此返回确定",因此我知道已建立连接.然后,我像下面这样制作一个简单的odbc_prepare:

This return 'ok' so I understand that the connection has been established. Then I make a simple odbc_prepare like the following:

$query="SELECT * FROM DATABASE.TABLE WHERE ID=1;
$result=odbc_prepare($as400,$query);

这引发了我致命错误:允许的内存大小用完了1048576000字节(试图分配140707423584261字节).

This throws me Fatal error: Allowed memory size of 1048576000 bytes exhausted (tried to allocate 140707423584261 bytes).

我已将php.ini文件上的memory_limit的值增加到1000M,它仍然引发相同的错误.我一直在网上冲浪,发现有人在64位版本上遇到问题,例如这篇文章:

I have incremented the value of memory_limit on the php.ini file to 1000M and it still throws the same error. I've been surfing on internet and I found people having problems with 64 bits versions like on this post: Linux odbc Fatal error: Allowed memory size but the query I'm executing doesn't have any null value.

信息

odbcinst -j命令:

odbcinst -j command:

DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

odbcinst.ini:

odbcinst.ini:

[iSeries Access ODBC Driver]
Description=iSeries Access for Linux ODBC Driver
Driver=/opt/ibm/iSeriesAccess/lib64/libcwbodbc.so
Setup=/opt/ibm/iSeriesAccess/lib64/libcwbodbcs.so
NOTE1=If using unixODBC 2.2.11 or later and you want the 32 and 64-bit ODBC drivers to share DSN's,
NOTE2=the following Driver64/Setup64 keywords will provide that support.
Driver64=/opt/ibm/iSeriesAccess/lib64/libcwbodbc.so
Setup64=/opt/ibm/iSeriesAccess/lib64/libcwbodbcs.so
Threading=2
DontDLClose=1
UsageCount=2

[iSeries Access ODBC Driver 64-bit]
Description=iSeries Access for Linux 64-bit ODBC Driver
Driver=/opt/ibm/iSeriesAccess/lib64/libcwbodbc.so
Setup=/opt/ibm/iSeriesAccess/lib64/libcwbodbcs.so
Threading=2
DontDLClose=1
UsageCount=1

odbc.ini为空白.

odbc.ini is blank.

看到iSeriesAccess驱动程序x64可能存在一些错误,我终于将其卸载了.然后,我安装了iSeriesAccess驱动程序x32.在安装新驱动程序之前,我制作了Debian多体系结构,并下载了ia32-libs(因为iSeriesAccess驱动程序x32缺少某些软件包).

Seeing that maybe the iSeriesAccess Driver x64 has some bugs I finally uninstalled it. Then I installed the iSeriesAccess Driver x32. Before installing the new driver I made my Debian multiarch and I downloaded the ia32-libs (because some packages were missing for the iSeriesAccess Driver x32).

使用新驱动程序,我会遇到另一个错误:
警告:odbc_connect():SQL错误:[unixODBC] [驱动程序管理器]无法打开lib'/opt/ibm/iSeriesAccess/lib/libcwbodbc.so':找不到文件,SQLConnect中的SQL状态为01000.

With the new driver I get another error:
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Can't open lib '/opt/ibm/iSeriesAccess/lib/libcwbodbc.so' : file not found, SQL state 01000 in SQLConnect.

我再次检查了lib'libcwbodbc.so'是否存在.我还对lib运行了命令ldd来查看是否缺少某些内容:

I have double checked that the lib 'libcwbodbc.so' exists. I also run the command ldd against the lib to see if there is something missing:

linux-gate.so.1 (0xf7763000)
libcwbcore.so => /opt/ibm/iSeriesAccess/lib/libcwbcore.so (0xf7557000)
libodbcinst.so.1 => /usr/lib/i386-linux-gnu/libodbcinst.so.1 (0xf7544000)
libdl.so.2 => /lib/i386-linux-gnu/i686/cmov/libdl.so.2 (0xf753e000)
libpthread.so.0 => /lib/i386-linux-gnu/i686/cmov/libpthread.so.0 (0xf7522000)
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xf7430000)
libm.so.6 => /lib/i386-linux-gnu/i686/cmov/libm.so.6 (0xf73ea000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xf73cd000)
libc.so.6 => /lib/i386-linux-gnu/i686/cmov/libc.so.6 (0xf721f000)
librt.so.1 => /lib/i386-linux-gnu/i686/cmov/librt.so.1 (0xf7216000)
libltdl.so.7 => /usr/lib/i386-linux-gnu/libltdl.so.7 (0xf720a000)
/lib/ld-linux.so.2 (0xf7766000)

如您所见,没有缺少的库.我想念什么?

As you could see there aren't missing libs. What am I missing?

最后,我安装了32位版本的Debian.在我看来,该问题取决于64位版本的IBM I Access Driver.我只是在新安装上遵循了相同的步骤,所以它就像一个魅力.希望对别人有帮助.

Finally, I installed the 32 bits version of Debian. As it looked to me the problem relied on the IBM I Access Driver of 64 bits version. I just followed the same steps on the new installation and it works like a charm. Hope it helps someone else.

推荐答案

这是#21286589的副本.仅仅因为您没有NULL值,并不意味着在使用不匹配的ABI时不会遇到问题.

This is a duplicate of #21286589. Just because you do not have a NULL value doesn't mean you won't run in to problems when using a mis-matched ABI.

这里的问题是,旧驱动程序仅设置64位指示符值的32位,而PHP读取了整个64位.在这里,PHP看到值为140707423584261,十六进制为0x7FF900000005.您可以看到最后4个字节是0x00000005,它是5,应该是返回的实际数据的长度.剩下的都是垃圾,因为驱动程序没有更改那些字节.

The problem here is that the old driver only sets 32-bits of the 64-bit indicator value and PHP reads the whole 64-bits. Here PHP sees the value 140707423584261, which is 0x7FF900000005 in hex. You can see the last 4 bytes are 0x00000005 which is 5 and should be the length of the actual data returned. The rest of it is garbage because the driver did not change those bytes.

正如我在对 Linux odbc致命错误的回答中提到的那样:允许的内存大小,您将需要从IBM i Access Client解决方案Linux应用程序包中获得新的ODBC驱动程序.此驱动程序遵循2.2.14版本以来unixODBC使用的完整64位ABI.新的驱动程序包还包含Debian .deb包,因此不再需要您引用的博客中的所有步骤.

As I mentioned in my answer for Linux odbc Fatal error: Allowed memory size, you will need to get the new ODBC driver from the IBM i Access Client Solutions Linux Application Package. This driver follows the full 64-bit ABI that unixODBC has used since 2.2.14. The new driver package also contains Debian .deb packages, so pretty much all the steps in the blog you referenced are no longer needed.

这篇关于odbc_prepare给出致命错误:允许的内存大小用尽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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