You’ll have to make the replacement engines components identical to the original engine - now ‘IF’ that can be done by transferring the parts from one to the other - you might get it to wok.
RepairPal Certified shops can diagnose and repair your 2006 Mazda 3. They provide transparent pricing with a minimum 12-month or 12,000-mile warranty on repairs and services.
I’d contact local salvage dealer - they’ve got access to the ultimate interchange information.