a related question, explained in code:
if($conditionA)
$linkA = mysql_connect(blah,blah,blah,true);
}
if($conditionB){
$linkB = mysql_connect(yadda,yadda,yadda,true);
}else{
$linkB = $linkA;
}
// then at the end of the script:
if(isset($linkA)){
mysql_close($linkA);
}
if(isset($linkB)){
mysql_close($linkB);
}
* * *
explanation
if $conditionA is true, then $linkA is a connection to database A.
if $conditionB is true, then $linkB is a connection to database B... else it's going to make its queries to database A.
The easiest way to reuse tons of code throughout my app is to assign $linkB = $linkA.
However, as this object is destructed, the second mysql_close() command fails, because $linkA gets closed before $linkB. You can't close something that's closed.
The warning is:
Warning: mysql_close(): 18 is not a valid MySQL-Link resource in yadda yadda yadda, line xx.
To see if a connection exists, "isset" isn't cutting it. Evidently it's easy to end up with a connection link that is closed.
How can I tell if a connection is open? Do I have to send it a query and see if it returns an error? That's just silly.