"it was horrible. Procedural, PHP inline with HTML, calls directly to mysql library functions"
There is NOTHING wrong with any of that! Making something more complicated does not make it better.
PS: I use a very strong templating library personally. It's called PHP.