Skip to content

How to Print Raw SQL query of Magento 2 format?

I am trying to print the raw SQL query of the below statement in Magento2 but am not able to do it. please find the statement

$connection = $this->getConnection(); // I am getting the connection
$tableName = $connection->getTableName(self::REQUESTED_TABLE); // getting the table
$data = ['is_legacy'=>1]; // Update ‘is_legacy=1’
$cond_val1 = 28; //for this id
$cond_val2 = 'sales_email_shipment_template'; // for this code

$where = ['template_id = ?' => (int)$cond_val1, 'orig_template_code = ?' => $cond_val2];

$updatedResult = $connection->update($tableName, $data, $where);

Note: I am able to perform the operation correctly.
Here I want to log the above MySQL query in a separate log file in Magento 2.