0

I want to store huge content in db and my sample text is 16129 characters in length when i tried to execute this query it is showing "error:The requested URL could not be retrieved" in firefox and "no-data received" in chrome.

I use LONGTEXT as datatype for column content in DB.

I also tried to execute the query directly in phpmyadmin with same huge content.It is working correctly.

The code is shown below.

    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)";
           //echo  $sql; exit;
            $db->query($sql);        
        }

But when I tried the same in Magento, $db->query($sql); does not able to run the query. Kindly advice on this.

6
  • 1
    What exactly are you trying to achieve? Looking at the above it doesn't follow good Magento development practice - you should never have to execute a query with raw SQL so I would suggest there is certainly going to be a better way to achieve your goal. Apr 10, 2013 at 14:30
  • @JonathanHussey Thanks, Yes i did not follow Mage::getModel to save it. When i tried with above code, It should work with query.But it does not...Kindly advice on this Apr 10, 2013 at 14:50
  • You are going to have to give more detail than you have here for anyone to be able to diagnose the problem, for instance errors messages generated when running the query() method. Apr 10, 2013 at 15:00
  • 1
    Try using $db->exec($sql) it executes the query and returns the amount of affected rows. Not sure if this will make a difference for you. Apr 10, 2013 at 15:57
  • @RickKuipers Thanks it works. You saved me. Apr 10, 2013 at 17:18

1 Answer 1

2

Try using $db->exec($sql) it executes the query and returns the amount of affected rows. I think $db->query() only gets executed when fetch is called as well...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.