break out of loop when meet condition then continue loop
Posted: Thu Jul 30, 2009 1:10 am
Hi,
I'm beginner in PHP.
Below is how I connect to multiple databases to query some status info.
Problem I have is, if the database is down, the code prints "Could not connect ..." and exits without connecting to rest of databases in DatabaseList. I'm not sure of a way to continue querying the rest of databases that are up.
What can I do to achieve this?
for ($row = 0; $row < $result_c; $row++)
{
$connection = mysql_connect($DatabaseList[$row]["db_hostname"], $DatabaseList[$row]["db_username"], $DatabaseList[$row]["db_password"]);
if (!$connection)
{
die ("Could not connect to database:".$DatabaseList[$row]["db_hostname"]."<br />". mysql_error());
} else {
//do something
}
I'm beginner in PHP.
Below is how I connect to multiple databases to query some status info.
Problem I have is, if the database is down, the code prints "Could not connect ..." and exits without connecting to rest of databases in DatabaseList. I'm not sure of a way to continue querying the rest of databases that are up.
What can I do to achieve this?
for ($row = 0; $row < $result_c; $row++)
{
$connection = mysql_connect($DatabaseList[$row]["db_hostname"], $DatabaseList[$row]["db_username"], $DatabaseList[$row]["db_password"]);
if (!$connection)
{
die ("Could not connect to database:".$DatabaseList[$row]["db_hostname"]."<br />". mysql_error());
} else {
//do something
}