as marcogmonteiro said, what your doing is not using the framework for what it was built to do.
Controllers should never access your database(s) directly.
Views should never access your database(s) directly.
Libraries should never access your database(s) directly.
This is what the Models are for. they perform CRUD operations on your data source(s).
Controllers should always be your skinniest part of your application.
Other wise your breaking the MVC pattern and might as well not be using a framework at all.