#43866 [Opn]: Can't define the connect timeout on mysqli extension class

From: Date: Thu, 17 Jan 2008 00:19:52 +0000
Subject: #43866 [Opn]: Can't define the connect timeout on mysqli extension class
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-121349@lists.php.net to get a copy of this message
ID: 43866 User updated by: basilio dot vera at softonic dot com Reported By: basilio dot vera at softonic dot com Status: Open Bug Type: MySQLi related Operating System: Linux RHEL4 PHP Version: 5.2.5 New Comment: Hi, I've found a solution for this problem. It can be solved with: class mysqli2 extends mysqli { public function __construct( $host, $user, $pass, $db ) { $this->init(); $this->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5); $this->real_connect( $host, $user, $pass, $db ); } } But you may consider review your docs, because it's and undocumented feature! Previous Comments: ------------------------------------------------------------------------ [2008-01-16 14:34:39] basilio dot vera at softonic dot com Sorry, the error message was: 'Couldn't fetch mysqli2' ------------------------------------------------------------------------ [2008-01-16 14:23:49] basilio dot vera at softonic dot com Description: ------------ I can't change the "MYSQLI_OPT_CONNECT_TIMEOUT" flag inside an extended class of mysqli. This is not really a bug, but a missed feature! Reproduce code: --------------- // I want some similar to this: $mysqli = mysqli_init(); $mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5); $mysqli->real_connect('localhost', 'my_user', 'my_password', 'world'); // My class that does many magic things. class mysqli2 extends mysqli { public function __construct( $host, $user, $pass, $db ) { parent::__construct( $host, $user, $pass, $db ); // Too late, the connection has been done before! $this->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5); } } // If I put the options call before the parent::__construct() call I get 'Couldn't fetch DbLink' error. // And, obviously, this does not work. class mysqli3 extends mysqli_init {} Expected result: ---------------- The connect timeout has been changed to 5 seconds. Actual result: -------------- The connect timeout has not been changed. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43866&edit=1

« previous php.bugs (#121349) next »