1

im having following code to get the battary status using WMIC commands.im getting our network all IP addreses from mysql database.when code runs..if there is remote computer which RPC server not available it throw a fatal error.what i want is if there is any error with a IP,dispaly that IP and custom error msg and continue to next IP without stopping from there.

$sel="select * from nmap_hosts_xml";
    $sel_r=mysql_query($sel);
    while($row1=mysql_fetch_array($sel_r))
    {
        $ip=$row1['address_addr'];
        $os=$row1['os_osmatch_name'];


        $obj = new COM ( "WbemScripting.SWbemLocator" ); 
$obj=$obj->ConnectServer($ip, "root/CIMV2","domain/Username","Password");
$battery=   $obj->ExecQuery("Select * from Win32_Battery");

foreach ( $battery as $wmi_bat )
{
    $bat = $wmi_bat->BatteryStatus;
}

echo $ip." ".$bat."<br>";

    }
DAM_86
  • 67
  • 8

1 Answers1

0

Add a try/catch block inside the loop.

Niche
  • 967
  • 5
  • 23
  • hi @niche im not that much familir with php error handling.can you direct me to proper example which is using try/catch within while loop? – DAM_86 May 23 '13 at 03:55
  • [Here](http://stackoverflow.com/questions/141560/should-try-catch-go-inside-or-outside-a-loop)'s a link to another thread related to your question. In your case, I'd put the try/catch block *inside* the loop because you're trying to output the result of the iteration through the IPs. – Niche May 23 '13 at 03:58
  • tnx @niche.i've solved the problem using your link.and i put try/catch inside the loop. – DAM_86 May 23 '13 at 04:10