Set database connection timeout in CodeIgniter 3

We work with 2 databases, our local database and an external database. But now our external database is not working (we are still in development, so it’s good that we encountered this problem), and now it tries to connect to the external database for 30 seconds, how can I change the database connection timeout to something like 1 - 2 seconds? I am using Codeigniter with PDO drivers in my databases. Is there anyone with a clean solution to this problem?

+5
source share
1 answer

This is not a document function, but you can do it from the database configuration file ( application/config/database.php ) by adding the options parameter, for example:

 $db['default']['options'] = array(PDO::ATTR_TIMEOUT => 5); 

Other settings that use the same internal mechanism (for example, PDO::MYSQL_ATTR_INIT_COMMAND set with $db['default']['stricton'] and PDO::MYSQL_ATTR_COMPRESS set with $db['default']['compress'] ), do not affect this.

If you want to dig deeper or check which parameters are set, you can write $this->options in db_connect in system/database/drivers/pdo/pdo_driver.php in system/database/drivers/pdo/pdo_driver.php , and also check database/drivers/pdo/subdrivers/pdo_mysql_driver.php .

+4
source

All Articles