Let us know the exact way to import bulk data to DB using queries.

closed as too broad by Mohit Kumar Arora, Piyush, Priyank, Manashvi Birla, Dhiren Vasoya Sep 26 '18 at 13:55

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


Write custom MYSQL query without using Model

Here is example how to write custom mysql query in Magento2.

Suppose we have table employee with fields emp_id, emp_name, emp_code and emp_salary.

Now use following code to run custom queries in magento2 without using model.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('employee'); //gives table name with prefix

//Select Data from table
$sql = "Select * FROM " . $tableName;
$result = $connection->fetchAll($sql); // gives associated array, table fields as key in array.

//Delete Data from table
$sql = "Delete FROM " . $tableName." Where emp_id = 10";

//Insert Data into table
$sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')";

//Update Data into table
$sql = "Update " . $tableName . "Set emp_salary = 20000 where emp_id = 12";

For more reference Click here

Not the answer you're looking for? Browse other questions tagged or ask your own question.