How to Get Category IDs from the product in Magento 2?

You can get the product category IDs from the product object using Magento 2.

You can retrieve all the category IDs assigned for products at any place, using the below code snippet.
Continue reading “How to Get Category IDs from the product in Magento 2?”

How to write a SQL Safe Query using quoteInto() method magento 2?

Using a SQL quoteInto() method, Write a Query using Magento standard way with SQL Safe quoted value.

You can avoid SQL injection attacks, no matter which database you use, is to separating the data value from the SQL statement. You can use ? to pass data in SQL query with the quoteInto() method.

Return Type: Always returns a string with SQL-safe quoted value placed into the original text.

You can use a given method in the direct SQL query for a safe quote with SQL conditions. Continue reading “How to write a SQL Safe Query using quoteInto() method magento 2?”

Write a fetchCol() Sql query in Magento 2.

Write a Mysql fetchCol() query using Magento standard way without using the Model file.

To Fetches the first column of all SQL result rows as an array.

Return Type: fetchCol() always returns as an array. Continue reading “Write a fetchCol() Sql query in Magento 2.”