MySQL Connections within if/else statements

software development


I was wondering if anyone knew how mysql_connect() acted within an if/else statement. Does it open the connection only if the if/else condition is met, or does it open a connection immediately, and just not query unless the if/else condition is met?

Is it any different if making a persistent connection? [mysql_pconnect()]

I ask because I’m trying to limit my connections to a database, and I hope by placing them within if/else statements i’ll be able to do so. (Could this effect the conueries in a positive manner?)


The former, in this situation:[code]$dbh = false;
if (boolean expression) {

true, now try to connect

$dbh = mysql_connect();
else {

false, do not try to connect


if ($dbh == false) {

no connection

[/code]It wouldn’t make much sense if the latter was true. But you fail to mention what part of the if/else statement. Obviously if you call mysql_connect() within the condition expression, the connection will be made even if other terms of the condition make the result false.

[code]if (mysql_connect() || true) {

always executed even if connection failed

else {

never executed

}[/code] :cool: Perl / MySQL / HTML+CSS