Check if database table exists or not using Magento 2.

Magento 2, When you deal with database table related stuff and first you want to check if a specific table exists or not in the database.

You need to use isTableExists() for getting table exists or not. using the above function you get the idea of table available or not.

Output: isTableExists() returns always boolean. true or false. Continue reading “Check if database table exists or not using Magento 2.”

Use of insertMultiple mysql query in Magento 2.

Write a Mysql insertMultiple query using Magento’s standard way to insert multiple rows/records at a single time.

You can write direct SQL query insertMultiple() without worrying about the Model operation for inserting multiple records in a specific table using below code snippet.

Return Type: insertMultiple() always returns an integer number for affected rows in a table. Continue reading “Use of insertMultiple mysql query in Magento 2.”

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?”