Hardware shut off of iPhone mic (eavesdropping prevention)
Is your iPhone jailbroken? If not, I am not aware of a single instance where an iPhone that is not jailbroken has been compromised in terms of its camera or microphone. 

The article you link to is about a laptop webcam, and this is a known risk and there are many examples of people's laptops being compromised (especially Windows models).

Assuming your iPhone is not jailbroken, then any apps that are designed to use your microphone need to request access to the microphone. If you do not give permission, then iOS does not allow them to use the microphone. You can also check these settings manually at any time by going to Settings > Privacy > Microphone.

In terms of what you're actually trying to do, this will not work without some sort of software modification. The reason is that the internal microphone is available unless you have attached a microphone (or headphones that also incorporate a microphone). If what you connect to the headphone socket does not contain a microphone, then the internal microphone is still available.