<?php use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $params = $_SERVER; $bootstrap = Bootstrap::create(BP, $params); $objectManager = $bootstrap->getObjectManager(); $state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); $resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); $connection = $resource->getConnection(); $sql = "Select * FROM customer_entity" ; $result = $connection->fetchAll($sql); print_r($result); ?>
Tag Archives: Query
Enable MySQL Query Caching
You can setup them in /etc/my.cnf (CentOS 7)
vi /etc/my.cnf
Append config directives as follows:
query_cache_size = 268435456 query_cache_type=1 query_cache_limit=1048576
In above example the maximum size of individual query results that can be cached set to 1048576 using query_cache_limit system variable. Memory size in Kb.
Restart the mysql service.
service mysqld restart
WordPress MySQL Query Delete All Trash Comments
delete from wp_comments where comment_approved=’trash’;
Mysql Permission To Single Table
GRANT SELECT,INSERT,UPDATE,DELETE ON database_name.table_name TO ‘USER’@’HOSTNAME’;
Magento Custom Query Modify Category Page Layout
Run the below given script . It will set the value “’three_columns’” to the field “Page Layout” of all categories .
$write = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$updateQry = “UPDATE catalog_category_entity_varchar SET value=’three_columns’ WHERE attribute_id=’61’ “;
$write->query($updateQry);
Magento Custom Query Insert Data
$write = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$insertQry = “INSERT INTO customer_entity_int (entity_type_id, attribute_id) VALUES(1, 224)”;
$write->query($insertQry);
Magento Custom Query Update Data
$write = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$updateQry = “UPDATE catalog_category_entity_varchar SET value=’three_columns’ WHERE attribute_id=’61’ “;
$write->query($updateQry);
Magento Custom Query Select Data
$read = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’);;
$selectQry = “SELECT * FROM catalog_category_entity”;
$write->query($selectQry);
How to write a Custom SQL Query Magento
To select the data
$read = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’);;
$selectQry = “SELECT * FROM catalog_category_entity”;
$write->query($selectQry);
To add/modify data
$write = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$updateQry = “UPDATE catalog_category_entity_varchar SET value=’three_columns’ WHERE attribute_id=’61’ “;
$write->query($updateQry);
Magento Custom Query
To select the data
$read = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’);;
$selectQry = “SELECT * FROM catalog_category_entity”;
$write->query($selectQry);
To add/modify data
$write = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$updateQry = “UPDATE catalog_category_entity_varchar SET value=’three_columns’ WHERE attribute_id=’61’ “;
$write->query($updateQry);