Hi!
From my experience - it's highly unlikely it's residing in the database. Especially if you take a closer look at the image you atatched - that's the template file, and a part from it that's nothing to do with database, so the strong suggestion here is that you have some file residing somewhere on the host that is adding these to every php file it finds, time and time again, which should be traced and removed, and only then evrything else would need to be cleaned up. Otherwise it would go back and infect as soon as you clean any one of these out.
Could you send over the apache access(not errors) logs for the past week or so for further assessment of what we're actually dealing with here?
Kind Regards,
Dobri
PS: Working through SSH is not a problem at all.
Also, it would most probably take a day to trace and clean, but I put one extra day, as it will need monitoring after cleanup.