1

Can anybody share good resource where I can see ways to call Stored Procedure from Magento 2 Code.

Thanks

1
0

The following GetCustomers() stored procedure illustrates the logic:

DELIMITER $$

CREATE PROCEDURE GetCustomers()
BEGIN
 SELECT customerName, creditlimit
 FROM customers;
    END$$

DB Connection:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$sql = 'CALL GetCustomers()'; //This is the main query
$result = $connection->fetchAll($sql); 

Hope this helpful. thanks. thumps up.

For more information: http://www.mysqltutorial.org/php-calling-mysql-stored-procedures/

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.