You need to book a connecting flight so you can stay airside and not go through immigration. It may cost a little more but you can avoid all the Thai Pass crap.
Visas can only be obtained out of Thailand with the exception of a 90 day O visa based in retirement, marriage,etc. You cannot get a tourist visa inside Thailand.