Zend Framework MySQL query() 插入长文本的问题

发布于 2024-10-14 20:29:34 字数 1622 浏览 7 评论 0原文

我有一个类:

class Content_IndexModel extends Zend_Db_Table_Abstract {}

并且我想使用以下方法将新行插入到某个表中:(

$this->getAdapter()->query();

我不能使用 insert() 方法,因为我需要放置“ON DUPLICATE KEY UPDATE ...”)

查询如下所示:

INSERT INTO some_table
VALUES (null, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam.')

如果我在文本字段中再添加一个字符我遇到了严重错误,apache 正在重新启动,日志为空,屏幕上没有任何内容 - 幻数是 342 - 如果我尝试插入更长的文本,服务器就会崩溃:

[Thu Jan 27 11:29:10 2011] [notice] Parent: child process exited with status 255 -- Restarting.
[Thu Jan 27 11:29:11 2011] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Thu Jan 27 11:29:11 2011] [notice] Server built: Dec 10 2008 00:10:06
[Thu Jan 27 11:29:11 2011] [notice] Child 2540: Child process is running
[Thu Jan 27 11:29:11 2011] [notice] Child 2540: Acquired the start mutex.
[Thu Jan 27 11:29:11 2011] [notice] Child 2540: Starting 64 worker threads.
[Thu Jan 27 11:29:11 2011] [notice] Child 2540: Starting thread to listen on port 80.

我尝试过几个不同的表 - 总是 342 可以,343 和更多 - 错误。两个包含 342 个字符的文本字段也可以,但当其中之一较长时 - 错误。另一个 PHP 版本,5.2.11 而不是 5.3.0 - 同样的错误。将 ZF 从 1.10.8 升级到 1.11.2 - 同样的错误。

当我使用 phpMyAdmin 运行此查询时,一切正常,所以我认为问题出在 ZF 上。

有什么想法吗?

I have a class:

class Content_IndexModel extends Zend_Db_Table_Abstract {}

and I want to insert new row into some table using:

$this->getAdapter()->query();

(I can't use insert() method because I need to put "ON DUPLICATE KEY UPDATE ...")

Query looks like this:

INSERT INTO some_table
VALUES (null, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam. Nulla quis pulvinar quam.')

And if I add one more char to text field I have mega-fatal-error, apache is restarting, logs are empty, nothing on screen - magic number is 342 - if I try to insert longer text server is crashing:

[Thu Jan 27 11:29:10 2011] [notice] Parent: child process exited with status 255 -- Restarting.
[Thu Jan 27 11:29:11 2011] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Thu Jan 27 11:29:11 2011] [notice] Server built: Dec 10 2008 00:10:06
[Thu Jan 27 11:29:11 2011] [notice] Child 2540: Child process is running
[Thu Jan 27 11:29:11 2011] [notice] Child 2540: Acquired the start mutex.
[Thu Jan 27 11:29:11 2011] [notice] Child 2540: Starting 64 worker threads.
[Thu Jan 27 11:29:11 2011] [notice] Child 2540: Starting thread to listen on port 80.

I've tried on few different tables - always 342 is ok, 343 and more - error. Two text fields with 342 chars are also ok, but when one of them is longer - error. Another PHP version, 5.2.11 instead of 5.3.0 - same error. Upgrading ZF from 1.10.8 to 1.11.2 - same error.

When I run this query with phpMyAdmin everything works ok, so I think problem is with ZF.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

装纯掩盖桑 2024-10-21 20:29:34

这有助于避免问题(但仍然不是问题的解决方案):

try {
    $this->insert(...);
} catch (Exception $e) {
    $this->update(...);
}

编辑:

此处找到的另一种解决方法:Zend_Db 查询在插入超过 358 个字符时崩溃

使用此:

$this->getAdapter()->getConnection()->query();

而不是此:

$this->getAdapter()->query();

This helps to avoid the problem (but still its not a solution for the problem):

try {
    $this->insert(...);
} catch (Exception $e) {
    $this->update(...);
}

EDIT:

another workaround found here: Zend_Db Query crashes on insert more than 358 characters

use this:

$this->getAdapter()->getConnection()->query();

instead of this:

$this->getAdapter()->query();
表情可笑 2024-10-21 20:29:34
this->getAdapter()->getConnection()->query();

当我更新查询时,我没有更新数据长文本,这对我有用

this->getAdapter()->getConnection()->query();

I have not update data longtext when I update query, It's work for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文