I have a php script
I want it to ping list of ips from a databse(using fping) and based on the status of the values to put them in a field(status) into the database(0 if down,1 if up)
i executed tghe script and it gives me this error:
Thread 1 - 17:51:01 26-04-2011 4.2.2.2 alive Couldn't execute query.
I cant see what 's wrong
this is the source of the php script:
Code:
<?php
require_once("conf.php");
$connection1 = mysql_connect($h, $u, $p) or die("Couldn't connect.");
$db_name = "status";
$table_name = "voip";
$connection = mysql_connect($h, $u, $p) or die("Couldn't connect.");
$db = mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$sql = "SELECT ip
FROM $table_name where thread = '1' ORDER BY ip
";
$result = mysql_query($sql,$connection) or die("Couldn't execute query1...");
while ($row = mysql_fetch_array($result)) {
$ip = $row['ip'];
$comanda = "/usr/bin/fping ". $ip;
$str=exec($comanda);
list($ip, $is, $status) = sscanf($str, "%s\t%s\t%s\n");
$dataa= date("H:i:s d-m-Y");
print "Thread 1 - ";
print $dataa;
print "\t";
print $ip;
print "\t\t";
print $status;
print "\n";
$dbname="status";
$db1 = mysql_select_db($dbname, $connection1) or die("Couldn't select database.");
$sql1 = "UPDATE voip SET status = '$status', lastupdate = '$dataa' WHERE ip = '$ip'";
$result1 = mysql_db_query($dbname,$sql1) or die("Couldn't execute query.");
}
?>
this is the database:
database: status
table: voip
fields: id ip status thread
1 4.2.2.2 1
2 4.2.2.2 1
3 4.2.2.2 1