views:

153

answers:

1

Hi, I'm using latest version of Xampp on 64bit Win7. The problem is that, when I use mysql_connect with "bool $new_link" set to true like so:

mysql_connect('localhost', 'root', 'my_password', TRUE);

script execution time increases dramatically (about 0,5 seconds per connection, and when I have 4 diffirent objects using different connections, it takes ~2 seconds).

Is setting "bool $new_link" to true, generally a bad idea or could it just be some problem with my software configuration.

Thank you.

//Edit: I'm using new link, because I have multiple objects, that use mysql connections (new objects can be created inside already existing objects and so on). In the end, when it comes to unsetting objects (I have mysql_close inside my __destruct() functions), I figured, that the only way to correctly clean up loose ends would be that all objects have their own connection variables. I just formated my PC so configuration should be default conf.

+1  A: 

Don't open a new connection unless you have a need for one (for instance, accessing multiple databases simultaneously).

Also you don't have to explicitly call mysql_close. I usually just include a function to quickly retrieve an existing db link (or a new one if none exists yet).

function &getDBConn() {
    global $DBConn;
    if(!$DBConn) $DBConn = mysql_connect(...);
    return $DBConn;
}
// now you can just call $dbconn = getDBConn(); whenever you need it
Rob