How to write a fetchPairs MySql query in Magento 2?

Write a Mysql fetchPairs() query using Magento standard way for fetching all SQL result rows as an array of key-value pairs.

You can write direct SQL query fetchPairs() without worrying about Model operation using below code snippet.

Return Type: fetchPairs() always return as an array with key-value pair as output. Continue reading “How to write a fetchPairs MySql query in Magento 2?”

Write a fetchAssoc mysql query in Magento 2.

Write a Mysql fetchAssoc() query using Magento standard way for Fetches all the SQL result rows as an associative array as an output.

You can write direct SQL query fetchAssoc() without worrying about Model operation using below code snippet.

Return Type: fetchAssoc() always returns as an array with the first column as the key and the entire row array as the value. Continue reading “Write a fetchAssoc mysql query in Magento 2.”

Write a fetchRow direct mysql query in Magento 2.

Write a Mysql fetchRow() query using Magento standard way for fetching the first row of the SQL result as an output.

You can get the first row as a result from the list of a resultant array using a query.

Direct SQL query fetchRow() without worrying about the Model operation.

Return Type: fetchRow() always returns as an array based on your query conditions. Continue reading “Write a fetchRow direct mysql query in Magento 2.”