CodeIgniter Forums
Using PDO connect has error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Using PDO connect has error (/showthread.php?tid=73010)



Using PDO connect has error - rfrkk - 03-09-2019

According to this document [link], following pdo setting will show an error:"Class '\CodeIgniter\Database\pdo\Connection' not found".

But, if i change to the default MySQLi setting that could work normally, i don't know what is wrong?

// use PDO
public $pdotest= [
        'DSN' => 'mysql:dbname=db1;host=localhost',
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => 'xxxx',
        'database' => '',
        'DBDriver' => 'pdo',
        'DBPrefix' => '',
        'pConnect' => false,
        'DBDebug' => (ENVIRONMENT !== 'production'),
        'cacheOn' => false,
        'cacheDir' => '',
        'charset' => 'utf8',
        'DBCollat' => 'utf8_general_ci',
        'swapPre' => '',
        'encrypt' => false,
        'compress' => false,
        'strictOn' => false,
        'failover' => [],
        'port' => 3306,
    ];

// use default mysql 5.7.24
public $default = [
        'DSN' => '',
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => 'root',
        'database' => 'db1',
        'DBDriver' => 'MySQLi',
        'DBPrefix' => '',
        'pConnect' => false,
        'DBDebug' => (ENVIRONMENT !== 'production'),
        'cacheOn' => false,
        'cacheDir' => '',
        'charset' => 'utf8',
        'DBCollat' => 'utf8_general_ci',
        'swapPre' => '',
        'encrypt' => false,
        'compress' => false,
        'strictOn' => false,
        'failover' => [],
        'port' => 3306,
    ];


RE: Using PDO connect has error - ciadmin - 03-09-2019

It may not be clear enough in the user guide, but CI4 only has 3 database drivers so far: mysql, postgres & sqlite3.
It doesn't have a PDO driver.

This is mentioned in the roadmap, where we are trying to determine which drivers to build out next or which we need help with.


RE: Using PDO connect has error - locofranco - 06-22-2020

Does this mean we can not use PDO connections? I am trying to connect to an MSSQL 2008 server. It appears I can connect to it with the DSN string fully set and declare DBDriver as "MySQLi". However, does that route limit what I can do with manual queries? Can I still get array results, execute Stored PRocedures, and access Views?


RE: Using PDO connect has error - jreklund - 06-22-2020

That's correct, you cannot use PDO at this time. Don't use another engine for you server, it uses specific instruction not available for your server, and it may lead to corrupted data.

You can help out by testing and/or developing the driver:
https://github.com/codeigniter4/CodeIgniter4/issues/503