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
}
break out of loop when meet condition then continue loop
Moderator: General Moderators
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: break out of loop when meet condition then continue loop
"die" kills the process.Try replacing it with "echo".
Re: break out of loop when meet condition then continue loop
Thanks cpetercarter.
I should understand the code before copying and pasting.
Re: break out of loop when meet condition then continue loop
You should. You could copy and paste some code that wipes your entire server. That'd be shameful.