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

时间:2011-01-27 11:03:10

标签: php mysql zend-framework zend-db zend-db-table

我有一个班级:

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上。

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

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

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

编辑:

此处找到另一种解决方法:Zend_Db Query crashes on insert more than 358 characters

使用它:

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

而不是:

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

答案 1 :(得分:0)

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

我更新查询时没有更新数据longtext,这对我有用