Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Couldn execute sql query
 
romanet
Jr. Member
 
Total Posts:  1
Joined:  2011-07-28
 

Hi all!  Immediately I apologize for my English. I work through an interpreter. Versed in mazhento and decided to write a function that automatically deletes old orders but was faced with poser. The following quote myself sql query it works but unfortunately not as necessary. This query removes all records from the database tables, but if you specify the WHERE he ceases to hold. I checked the query directly in the database everything works as it should, but from the Magenta he flatly refuses to run. I understand that it does Magenta block such action. However, if you can tell me how to get around this block.

works:)

$connection Mage::getSingleton(\'core/resource\')->getConnection(\'core_write\');
$connection->beginTransaction();
$delete $connection->query(\'

SET FOREIGN_KEY_CHECKS=0;

ALTER TABLE `catalogsearch_query` AUTO_INCREMENT=1;


DELETE FROM sales_flat_order;
DELETE FROM sales_flat_order_address;
DELETE FROM sales_flat_order_grid;
DELETE FROM sales_flat_order_item;
DELETE FROM sales_flat_order_payment;
DELETE FROM sales_flat_order_status_history;


ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;

not work:(

$connection Mage::getSingleton(\'core/resource\')->getConnection(\'core_write\');
$connection->beginTransaction();
$delete $connection->query(\'

SET FOREIGN_KEY_CHECKS=0;

ALTER TABLE `catalogsearch_query` AUTO_INCREMENT=1;


DELETE FROM sales_flat_order WHERE entity_id=20;
DELETE FROM sales_flat_order_address WHERE parent_id=20;
DELETE FROM sales_flat_order_grid WHERE entity_id=20;
DELETE FROM  sales_flat_order_item WHERE order_id=20;
DELETE FROM  sales_flat_order_payment WHERE entity_id=20;
DELETE FROM   sales_flat_order_status_history WHERE parent_id=20;


ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;


\'
);
If you run this query directly in the database all the work is over.
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top