I'm extending mysqli in a database class. I've noticed that calling the parent constructor takes nearly 2 seconds. It is possible, I suppose, that it is my environment since I am developing on my desktop prior to deployment. But that does not seem very likely to me.
Environment:
- OS - Windows 7 Pro
- WAMP server
- Apache/2.2.17 (Win32)
- PHP 5.3.4
- MySql ver 5.1.53
- NetBeans IDE 6.9.1
The code in question:
class DGMysqliLink extends MySQLi
{
public function __construct($aDSN)
{
// Construct the DSN
$aDSN['dbhost'] = (empty($aDSN['dbhost']))?ini_get("mysqli.default_host"):$aDSN['dbhost'];
$aDSN['dbuser'] = (empty($aDSN['dbuser']))?ini_get("mysqli.default_user"):$aDSN['dbuser'];
$aDSN['dbpass'] = (empty($aDSN['dbpass']))?ini_get("mysqli.default_pw"):$aDSN['dbpass'];
$aDSN['dbname'] = (empty($aDSN['dbname']))?'':$aDSN['dbname'];
$aDSN['dbport'] = (empty($aDSN['dbport']))?ini_get("mysqli.default_port"):$aDSN['dbport'];
$aDSN['dbsock']= (empty($aDSN['dbsock']))?ini_get("mysqli.default_socket"):$aDSN['dbsock'];
// Instantiate the object by invoking the parent's constructor.
// This takes nearly 2 seconds
parent::__construct($aDSN['dbhost'],$aDSN['dbuser'],$aDSN['dbpass'],
$aDSN['dbname'],$aDSN['dbport'],$aDSN['dbsock']);
// If there are any errors, deal with them now
if($this->connect_error){/* Do some stuff */}
}
}
Why does calling this constructor take so long and how can I fix it?
// Construct the DSN $aDSN['dbhost'] = 'localhost'; $aDSN['dbuser'] = 'dbuser'; $aDSN['dbpass'] = 'dbpass'; $aDSN['dbname'] = 'dbname'; $oDBC = new mysqli($aDSN['dbhost'],$aDSN['dbuser'],$aDSN['dbpass'],$aDSN['dbname']); – Ron G May 19 '12 at 21:55