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();
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);
  • I am ruuning that code in helper but not works – Mahmood Rehman Jul 17 '13 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 ? – Mahmood Rehman Jul 17 '13 at 5:57
  • I can't figure out whats your problem, please give your solution, how can you separated them. – mageUz Jul 17 '13 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'); – Mahmood Rehman Jul 17 '13 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 Jul 17 '13 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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