Mysql 如何在magento中执行大型sql查询?

Mysql 如何在magento中执行大型sql查询?,mysql,magento,Mysql,Magento,我想在db中存储大量内容,我的示例文本长度为16129个字符,当我尝试执行此查询时,它在firefox中显示“错误:无法检索请求的URL”,在chrome中显示“未收到数据” 此外,我使用LONGTEXT作为数据库中文本的数据类型 我还尝试在phpmyadmin中直接执行查询,因为它工作正常 代码如下所示 public function _getConnection($type = 'core_write') { return Mage::getSingleton('core/r

我想在db中存储大量内容,我的示例文本长度为16129个字符,当我尝试执行此查询时,它在firefox中显示“错误:无法检索请求的URL”,在chrome中显示“未收到数据”

此外,我使用
LONGTEXT
作为数据库中文本的数据类型

我还尝试在phpmyadmin中直接执行查询,因为它工作正常

代码如下所示

public function _getConnection($type = 'core_write') {
        return Mage::getSingleton('core/resource')->getConnection($type);
    }

public function testdbAction(){
        $db = $this->_getConnection();
        $current_time=now();
        $text="The European languages are members of the same family......  ...Europe uses the same vocabulary. The ";//text is 16129 characters in length
        $sql = "INSERT into test(`usercontent_id`,`app_id`,`module_id`,`customer_id`,`content`,`created_time`,`updated_time`,`item_id`,`index_id`,`position_id`) VALUES (NULL, 15, 9,2,'" .$text. "','" . $current_time . "','" . $current_time . "',1003,5,4)";
        $db->query($sql);        
    }

我该怎么处理?任何建议或帮助。

尝试使用
$db->exec($sql)
而不是
$db->query($sql)

来处理数据库结构和数据Magento有一个专用位置。它被称为安装/升级脚本。它是用来跟踪模块版本的,以便于更新。因此,您应该使用脚本来添加新数据

这里有一个例子

模块的config.xml:


<modules>
    <My_Module>
        <version>0.0.1</version>
    </My_Module>
</modules>
<global>
    <resources>
        <my_module_setup>
            <setup>
                <module>My_Module</module>
                <class>Mage_Core_Model_Resource_Setup</class>
            </setup>
         </my_module_setup>
    </resources>
</global>
就这样。这是在Magento中将自定义数据添加到数据库中的一种干净而合适的方法

如果您想使用表单定期保存用户输入,那么我建议您创建w模型、资源模型和集合,并在config.xml中定义实体。有关更多信息,请参阅Alan Storm的文章,如


我希望我正确理解了您的问题。

Magento现在有了自己的StackExchange站点:由于您有testdbAction(),看起来您正在控制器中运行此站点。如果是,您的输出是什么?如果用echo替换testdbAction()函数的内容,会发生什么情况?我试着运行大量内容,并使用$db->query($sql)运行查询;但magento无法运行它。它显示“无法检索请求的URL”。

$this->startSetup();

$text = <<<TEXT
YOUR LONG TEXT GOES HERE
TEXT;

$this->getConnection()
    ->insert(
        $this->getTable('test'),
        array(       
             'usercontent_id' => null,
             'app_id' => 15,
             'content' => $text,
             //other fields in the same fashion
        )
    );

$this->endSetup();