1

Hi i write valid queries for data insertion but not successeded.If i print that query and excute it on sql server it works.I didn't figure out why this not works. This is my table structure.

CREATE TABLE `findyoursizevalues` (        
                      `findyoursize_id` int(11) DEFAULT NULL,  
                      `key_val` varchar(200) DEFAULT NULL,     
                      `min_values` int(10) DEFAULT NULL,       
                      `max_values` int(10) DEFAULT NULL        
                    ) ENGINE=InnoDB DEFAULT CHARSET=latin1.

This is different queries i use for insertion but no output.

$connectionWrite = Mage::getSingleton('core/resource')->getConnection('core_write');
        $tableName = $connectionWrite->getTableName('findyoursizevalues');
        $connectionWrite->beginTransaction();
        $data = array();
        $data['findyoursize_id']= $fid;
        $data['key_val']=$key;
        $data['min_values']=$min_val;
        $data['max_values']=$max_val;

        $connectionWrite->query("insert into ".$tableName." values ('1','bbb','2','3')"); //query 1
        $connectionWrite->query(" insert into $tableName set findyoursize_id =$fid,key_val='".$key."',min_values=$min_val,
            max_values=$max_val ");// query 2
        $connectionWrite->insert($tableName, $data); // query 3
        $connectionWrite->commit();

1 Answer 1

2

I just used following snippet in my model and sql installer and it worked fine.

/**
* @var $resource Mage_Core_Model_Resource
*/
$resource     = Mage::getSingleton('core/resource');
$connection   = $resource->getConnection('core_write');
$table        = $resource->getTableName('some_table_name');

$query        = "INSERT INTO {$table} (`entity_id`,`entity_type_id`,`attribute_id`,`value`,`store_id`) VALUES ($entity_id, $entity_type_id, $attribute_id, $value, $store_id);";
$connection->multiQuery($query);
7
  • I am ruuning that code in helper but not works Commented Jul 17, 2013 at 5:48
  • I found the issue when i use single instance like $connectionWrite it not works but if i use seperate variables for connection and write adapter then it works.As there any difference ? Commented Jul 17, 2013 at 5:57
  • I can't figure out whats your problem, please give your solution, how can you separated them.
    – mageUz
    Commented Jul 17, 2013 at 6:11
  • when i use this type connection $resource = Mage::getSingleton('core/resource'); $connection = $resource->getConnection('core_write'); .it works, but this type connection not work for me $connectionWrite = Mage::getSingleton('core/resource')->getConnection('core_write'); Commented Jul 17, 2013 at 6:18
  • Strange behaviour, I don't know why? Check this one: $resource = Mage::getSingleton('core/resource'); $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
    – mageUz
    Commented Jul 17, 2013 at 6:23

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.