![]() |
What is the right way to use PDO directly in CodeIgniter 3? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: What is the right way to use PDO directly in CodeIgniter 3? (/showthread.php?tid=69014) |
What is the right way to use PDO directly in CodeIgniter 3? - aventador - 09-27-2017 I prefer to use PDO rather than codeigniter provided db class. i want to execute fetchAll(), prepare() statements which is not supported in db class provided by codeigniter If i want to use PDO directly , should i place $db = new PDO($dsn,$username,$password); in every model class ? . Is that bad ? What is the right way? i am a newbie . RE: What is the right way to use PDO directly in CodeIgniter 3? - skunkbad - 09-27-2017 Extend PDO in a library. Load or autoload the library and make your connection in the constructor using custom configuration. You can see examples of this all over the internet. Since you're a newbie, this is a good way to learn how to use libraries with CodeIgniter. The problem would be that some other CodeIgniter libraries (or at least 1) depend on the CodeIgniter database connection. Sessions do if you use the database sessions. |