If I understand you correctly, you may create a widget to deal with this (see MainMenu included in the yiic webapp as an example). You may put your DB accessing logic in the class.
You may also consider write a base controller which would serve the common content for the layout. And then all your other controllers extend from this base class. In the layout, you can call $this->xyz() to do the job you want.