I've got a php class that needs a PDO instance to become passed to it's constructor. The code could be something similar to this:

$pdo = new PDO($host, $username, $password);
$myclass = new myClass($pdo);

The issue I have got is integrating this with CI. CI auto loads it's database class which handles all DB connections and it is utilized with


It might be quite simple basically could instantiate myClass using the CI database object, however it appears to contain much more stuff than simply the PDO instance. I have attempted

 $myClass = new myClass($this->db);

also it does not enjoy it whatsoever. I understand I possibly could rewrite myClass to gain access to the CI db object directly (i.e. without needing to possess a new connection passed into it), however i don't actually want to start that mammoth undertaking!

So, it is possible to method to make use of the CI db class for this function? Wouldn't it make a difference basically just produced a brand new PDO instance as above when the CI database library has already been loaded?

There is not a good way to obtain the current PDO connection from CI's database class. However, you do not always need that. You may create your personal PDO connection and pass that directly into your custom class. You will have two live connections towards the DB, which is not ideal, however, you could most likely work that out.