如何在codeigniter中运行并发数据库连接正常mysqli和自定义pdo [重复]

This question already has an answer here:

Afternoon all. I have a strange question. I need to have two connections to our db in codeigniter instance. I need to have the standard ci method but i also need to create a pdo class instance for use in new feature setup. We are unfortunately in the position where we have to run a v1.0 system using the old db connectivity and a new v2.0 system using a pdo db object.

How can I go about creating a global instance of this pdo class so that it only gets instantiated once per process call to codeigniter.

</div>

you should add another DB in application/config/database.php and change dbdriver and hostname like

$db['pdodb']['hostname'] = "mysql:host=localhost'";
$db['pdodb']['username'] = "root";
$db['pdodb']['password'] = "";
$db['pdodb']['database'] = "your_db";
$db['pdodb']['dbdriver'] = "pdo";
$db['pdodb']['dbprefix'] = "";
$db['pdodb']['pconnect'] = TRUE;
$db['pdodb']['db_debug'] = FALSE;
$db['pdodb']['cache_on'] = FALSE;
$db['pdodb']['cachedir'] = "";
$db['pdodb']['char_set'] = "utf8";
$db['pdodb']['dbcollat'] = "utf8_general_ci";
$db['pdodb']['swap_pre'] = "";
$db['pdodb']['autoinit'] = TRUE;
$db['pdodb']['stricton'] = FALSE;

and you can load database like this

$pdodb= $this->load->database('pdodb', TRUE);

and finally you can execute query like this

$query = $pdodb->select('col1, col2,col3')->get('your_table');

for more information about multiple database