In my code I've got a

$connection->query("TRUNCATE TABLE $tableName");

Works great. However using the official https://github.com/magento/magento-coding-standard ruleset it showed the following warning.

Possible raw SQL satement.

Which I understand because it is.

My question is: is it possible to truncate a table within Magento without using raw SQL?


You can simply use $connection->truncateTable($table)


  • You know where I can find this method? – Dominic Xigen Jun 8 '19 at 7:18
  • It's from class \Magento\Framework\DB\Adapter\Pdo\Mysql – Khoa TruongDinh Jun 8 '19 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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