I can’t say for certain without having to extensively digging through your code (that’s your responsibility), but it looks like your code might have already closed the database connection by the time you want to do any queries. Here is a topic from the CodeIgniter forums about this: https://forum.codeigniter.com/thread-81.html