How to use pdo in codeigniter?

As I know, PDO support has been added to codeigniter recently, but I cannot find any documentation or tutorial on how to actually use it. Can anyone tell how I can use it?

+4
source share
2 answers

You can edit /application/config/database.php and enable the PDO driver:

 $db['default']['hostname'] = 'pgsql:localhost'; // or mysql:localhost // or sqlite::memory: $db['default']['dbdriver'] = 'pdo'; 

If you want to directly connect to an active database connection. This might work, but I'm not a CI developer .. so no guarantees. I tried to understand that the code is rotting the brain , but I suspect that I failed. I am not good at PHP4 + eval() :

 $CI = get_instance(); var_dump($CI->db->conn_id); // should show that conn_id is instance of PDO 
+3
source

Well, since CodeIgniter is just a PHP framework, nothing prevents you from using it natively, as in $pdo = new PDO(...); .

However, when they say that PDO is now supported, I think they mean that their regular Database class now uses PDO (and not MySQLi or such).

+2
source

Source: https://habr.com/ru/post/1403330/


All Articles