开发者

In PHP, what corresponds to mysql.connect_timeout in MySQLi?

We recently ported some code we have to use PHP's MySQLi extension ins开发者_JS百科tead of the regular mysql. This code connects to a database that occasionally might not be responding, so we set this variable on PHP.ini:

mysql.connect_timeout = 3

That way if it takes more than 3 seconds to connect to that database, it simply gives up. However this doesn't seem to work for MySQLi. What would be the corresponding setting for MySQLi?

Thank you in advance.


You should use MYSQLI_OPT_CONNECT_TIMEOUT as reported here.

Here's a small example from this thread:

class mysqli2 extends mysqli
{
    public function __construct( $host, $user, $pass, $db, $port=3306 )
    {
        parent::init();
        parent::options( MYSQLI_OPT_CONNECT_TIMEOUT, 5 );
        parent::real_connect( $host, $user, $pass, $db, $port );
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜