5

We are working with 2 databases, our local database and an external database. But now our external database is down (we're still under development so it's good we came across this issue) and it now tries to connect to the external database for 30 seconds, how can I change the connection timeout of the Database to something like 1 - 2 seconds? I am using Codeigniter with the PDO drivers on my databases. Is there anyone with a clean solution for this problem?

4
  • Try this php.net/manual/en/… Commented Sep 17, 2015 at 7:14
  • I'm not using mysql @Scorpion Commented Sep 17, 2015 at 12:23
  • Have you tried setting PDO::ATTR_TIMEOUT? What is your database though? Commented Sep 19, 2015 at 19:10
  • That's one way to fix the issue, but I don't know if you're using codeigniter, it lets you choose between multiple drivers, (mysql, mysqli and PDO). I would like to know if it's possible to fix this issue without editting to core (which would be the PDO driver as I am using PDO to talk to a Mysql database) @user3584460 Commented Sep 19, 2015 at 19:15

1 Answer 1

11
+100

It is not a documented feature, but you can do this from the database config file (application/config/database.php) by adding options setting e.g.:

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

The other settings which use the same internal mechanism (e.g. PDO::MYSQL_ATTR_INIT_COMMAND set with $db['default']['stricton'] and PDO::MYSQL_ATTR_COMPRESS set with $db['default']['compress']) are not affected by this.

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

Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I was looking for, working like a charm! Thanks alot!! I cannot yet give you the bounty but will do so once I can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.