PDO Connection Test

前端 未结 4 1046
难免孤独
难免孤独 2020-11-27 07:04

I am writing an installer for one of my apps and I would like to be able to test some default database settings.

Is this possible using PDO to test valid and invalid

4条回答
  •  伪装坚强ぢ
    2020-11-27 07:23

    As @Sascha Galley already mentioned you should set error mode to exception mode. However, you should also set up PDO::ATTR_TIMEOUT attribute to prevent a long time waiting for response in some cases.

    Although documentation says that behavior of this attribute is driver-dependent in case of MySQL it's a connection timeout. You won't find anything about it documentation but here's a short snippet from driver's source code:

    long connect_timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, 30 TSRMLS_CC);
    

提交回复
热议问题