0

I've got a particular need to copy data from catalog_product_entity_varchar into catalog_product_entity_decimal for a particular attribute in Magento

I'm currently running a script in PHP with the following code:

$sql1 =     (" Insert into `catalog_product_entity_varchar` (`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) 

            select `entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value` from `catalog_product_entity_decimal`

            where   `attribute_id` = '230' ");

mysql_query($sql1);

$sql2 = ("DELETE FROM `catalog_product_entity_decimal` where `attribute_id` = '230' "); 
mysql_query($sql2);

the statements work if entered directly in MySQL, however when executed via PHP they fail - am I missing something?

1

it doesn't work because you are not connected to a database.

To run this from a Magento environment do this:

$resource = Mage::getSingleton('core/resource');
$connection = $resource->getConnection('core_write');

//your sqls here

$connection->query($sql1);
$connection->query($sql2);
| improve this answer | |
  • please assume that I am connected and that I'm just not posting the database connection details here. – Duncan Wardlaw Feb 13 '15 at 12:18
  • @DuncanWardlaw. Then describe the error you get. "fail" can mean a lot of things. – Marius Feb 13 '15 at 12:21
  • when running the code inside the ("") for either query directly in the SQL panel of mysql - there is no error message and the instruction is carried out, data is moved or deleted appropriately. when running the PHP file however, there is still no error message, however changes are not reflected in the database when running, one or both queries – Duncan Wardlaw Feb 13 '15 at 12:22
  • then, are you sure you are connected to the right database? – Marius Feb 13 '15 at 12:25
  • definately, I'm pulling data from the same database but in different areas using a single include script for database access for the whole script – Duncan Wardlaw Feb 13 '15 at 12:28
0

it appears that the code was correct but something was wrong with how my ftp client was saving data, I removed the code and re-pasted it from the code I put in my question here, re-ran it and it's working...

Not sure why however as no changes have been made

| improve this answer | |

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.