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

2 Answers 2

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);
5
  • please assume that I am connected and that I'm just not posting the database connection details here. Commented Feb 13, 2015 at 12:18
  • @DuncanWardlaw. Then describe the error you get. "fail" can mean a lot of things. Commented Feb 13, 2015 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 Commented Feb 13, 2015 at 12:22
  • then, are you sure you are connected to the right database? Commented Feb 13, 2015 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 Commented Feb 13, 2015 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

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.