CodeIgniter Forums
Access CodeIgniter Database Class directly - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Access CodeIgniter Database Class directly (/showthread.php?tid=54122)



Access CodeIgniter Database Class directly - El Forum - 08-23-2012

[eluser]ColonelChlorine[/eluser]
Does anyone have tips on how to access the CodeIgniter database classes/functions directly? I am working with PHPUnit and trying to test some of my classes that depend on

Code:
$CI =& get_instance();
$CI->db->query('blahblahblah');

It's not actually like that, because I use dependency injection to put the database into each class ... but in princple I need access to the fully instantiated class normally referenced by:

Code:
$this->db

I don't need the rest of the MVC framework, just the database functionality. I have tried things like requiring just the config/database.php file, and the system/database/DB.php, and working with that ... but it seems everything is so woven together I can't access the database without loading the entire framework. Gah!

Am I up !@#% creek? Looking forward to ideas/responses.


Access CodeIgniter Database Class directly - El Forum - 08-23-2012

[eluser]CroNiX[/eluser]
Have no idea if it works or not...it's also old but might point you in the right direction...
http://hasin.me/2007/06/13/using-activerecord-library-separately-from-codeigniter/


Access CodeIgniter Database Class directly - El Forum - 08-23-2012

[eluser]ColonelChlorine[/eluser]
Hi CroNiX, yeah I finally figured out something very similar to that. I would say that pretty much solves the issue. I was able to get it to work.