Fetchall() mysql query in Magento 2.

Mysql fetchAll() query using Magento standard way for fetch all the records of the custom query.

You can fetch all the selected record from the table using direct SQL query fetchAll() without worry about the Model operation.

Return Type: fetchAll() always return as array based on your query conditions. Continue reading “Fetchall() mysql query in Magento 2.”

Insert/add record using insert query via resourceConnection in Magento 2.

You can create custom insert query using Magento 2 to add/create a new record in database table via ResourceConnection class.

Using the Insert query, You can add a new record to the table using direct SQL query insert() without going to model operation. Continue reading “Insert/add record using insert query via resourceConnection in Magento 2.”

Use of fetchOne() method in sql query Magento 2.

You can run a direct SQL query for fetching only first value using fetchOne() method.

fetchOne() Fetches the first column of the first row of the SQL result as output.

You can use direct SQL query for the fetch the first column of the first row using below way, Get Product id by Product SKU,

Output is 1. //entity_id for SKU 24-MB01

Check for other Direct SQL Query in Magento 2