当选定的行具有NULL值时

时间:2019-04-16 14:28:39

标签: php laravel docker odbc ibm-midrange

我正在尝试将Laravel 5.7项目连接到我们的iSeries数据库。我的运行环境是在Linux环境中运行的Docker中。每当我尝试对包含NULL值的表行执行SELECT时,都会出现以下错误:

Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967320 bytes)

将表中的NULL值替换为''或其他任何值,按预期方式工作,所有值均正确返回。该表仅包含10行数据。

我的控制器查询代码:

use App\Notification;
$notifications = Notification::where('user_id', '=', $currentUser)->orderBy('id', 'desc')->get();

我的表格up()迁移:

Schema::create('notifications', function (Blueprint $table) {
    $table->increments('id');
    $table->string('user_id');
    $table->string('type');
    $table->integer('severity');
    $table->text('message');
    $table->string('link')->nullable();
    $table->timestamp('read_at')->nullable();
    $table->timestamps();
    $table->softDeletes();
});

我的database.php连接数组:

'connections' => [
    'db2' => [
        'driver' => 'db2_ibmi_odbc',
        // or 'db2_ibmi_ibm' / 'db2_zos_odbc' / 'db2_expressc_odbc
        'driverName' => '{iSeries}',
        // or '{iSeries Access ODBC Driver}' / '{IBM i Access ODBC Driver 64-bit}' / '{IBM DB2 ODBC DRIVER}
        'host' => 'redacted',
        'username' => 'ROBERT',
        'password' => 'password',
        'database' => 'ROBERT',
        'prefix' => '',
        'schema' => 'ROBERT',
        'port' => 446,
        'date_format' => 'Y-m-d H:i:s.u',
        // or 'Y-m-d H:i:s.u' / 'Y-m-d-H.i.s.u'...
        'odbc_keywords' => [
            'SIGNON' => 3,
            'SSL' => 0,
            'CommitMode' => 2,
            'ConnectionType' => 0,
            'DefaultLibraries' => '',
            'Naming' => 0,
            'UNICODESQL' => 0,
            'DateFormat' => 5,
            'DateSeperator' => 0,
            'Decimal' => 0,
            'TimeFormat' => 0,
            'TimeSeparator' => 0,
            'TimestampFormat' => 0,
            'ConvertDateTimeToChar' => 0,
            'BLOCKFETCH' => 1,
            'BlockSizeKB' => 32,
            'AllowDataCompression' => 1,
            'CONCURRENCY' => 0,
            'LAZYCLOSE' => 0,
            'MaxFieldLength' => 15360,
            'PREFETCH' => 0,
            'QUERYTIMEOUT' => 1,
            'DefaultPkgLibrary' => 'QGPL',
            'DefaultPackage' => 'A /DEFAULT(IBM),2,0,1,0',
            'ExtendedDynamic' => 0,
            'QAQQINILibrary' => '',
            'SQDIAGCODE' => '',
            'LANGUAGEID' => 'ENU',
            'SORTTABLE' => '',
            'SortSequence' => 0,
            'SORTWEIGHT' => 0,
            'AllowUnsupportedChar' => 0,
            'CCSID' => 819,
            'GRAPHIC' => 0,
            'ForceTranslation' => 0,
            'ALLOWPROCCALLS' => 0,
            'DB2SQLSTATES' => 0,
            'DEBUG' => 0,
            'TRUEAUTOCOMMIT' => 0,
            'CATALOGOPTIONS' => 3,
            'LibraryView' => 0,
            'ODBCRemarks' => 0,
            'SEARCHPATTERN' => 1,
            'TranslationDLL' => '',
            'TranslationOption' => 0,
            'MAXTRACESIZE' => 0,
            'MultipleTraceFiles' => 1,
            'TRACE' => 0,
            'TRACEFILENAME' => '',
            'ExtendedColInfo' => 0,
        ],
        'options' => [
            PDO::ATTR_CASE => PDO::CASE_LOWER,
            PDO::ATTR_PERSISTENT => false,
            //PDO::I5_ATTR_DBC_SYS_NAMING => false,
            //PDO::I5_ATTR_COMMIT => PDO::I5_TXN_NO_COMMIT,
            //PDO::I5_ATTR_JOB_SORT => false,
            //PDO::I5_ATTR_DBC_LIBL => '',
            //PDO::I5_ATTR_DBC_CURLIB => '', 
        ]
    ],
........more, unused connections

我正在使用cooperl22 / laravel-db2服务提供商。

我的DockerFile:

FROM php:7.2-fpm-stretch

ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /tmp

ADD php/www.conf /usr/local/etc/php-fpm.d/www.conf
ADD php/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
ADD os/freetds.conf /etc/freetds/freetds.conf
ADD os/ldap.conf /etc/ldap.conf 
ADD os/main.cf /etc/postfix/main.cf
ADD iseriesaccess_7.1.0-1.0_amd64.deb /

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y postfix git libssh2-1 libssh2-1-dev telnet autoconf unixodbc-dev \
unixodbc odbcinst freetds-bin freetds-dev tdsodbc ghostscript net-tools libldap2-dev zip unzip && \
pecl install ssh2-1.1.2

RUN ln -s /usr/local/bin/php /usr/bin/php
RUN ln -s /usr/lib/x86_64-linux-gnu /usr/lib64
RUN dpkg -i /iseriesaccess_7.1.0-1.0_amd64.deb

RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr/ && \
docker-php-ext-install pdo_odbc pdo_mysql ldap

ADD os/odbc.ini /etc/odbc.ini
ADD os/odbcinst.ini /etc/odbcinst.ini

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

CMD ["php-fpm"]

EXPOSE 5000

如您所见,我正在使用iseriesaccess_7.1.0-1.0_amd64.deb驱动程序。

看看其他答案,提高php内存限制不是一种选择。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

假设您使用的是PHP7.2,请尝试增加位于memory_limit上的php.ini文件上的/etc/php/7.2/cli/php.ini的值,该路径将包含您的php版本。您可以增加它直到您的内存需求已满(无限代表-1)。但是请记住,这不是一个好习惯。