Replaced SQL sprintf's with data bindings to allow use with Postgresql PDO backend.