Welcome Guest, Not a member yet? Register   Sign In
Using PDO connect has error
#1

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,
    ];
Reply
#2

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.
Reply
#3

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?
Reply
#4

(This post was last modified: 06-22-2020, 10:52 AM by jreklund.)

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB