Edgar,

The Learning Center Multi-Tenancy lesson has a full workspace to download with complete examples (one for single DB and another for multi DB). I'd suggest actually getting that example working and then taking what you learned over into your application.