Estoy haciendo un scrip de php donde puedan ver las diferentes direciones si estan ONLINE o OFFLINE y esto deseo que se deposite en una basa de datos de MySql La estrutura de mi tabla solo tiene dos columnas que son: Online_Status y ip
Este es el codigo de php, cuando lo ejecuto si me muestra las IP si estan ONILINE o OFFLINE pero no me lleva nada ala base de datos.
<?php
$conn=mysqli_connect("IP","login","password","baseDatos");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
class CheckDevice {
public function myOS(){
if (strtoupper(substr(PHP_OS, 0, 3)) === (chr(87).chr(73).chr(78)))
return true;
return false;
}
public function ping($ip_addr){
if ($this->myOS()){
if (!exec("ping -n 1 -w 1 ".$ip_addr." 2>NUL > NUL && (echo 0) || (echo 1)"))
return true;
} else {
if (!exec("ping -q -c1 ".$ip_addr." >/dev/null 2>&1 ; echo $?"))
return true;
}
return false;
}
}
$ip_addr = array (10.49.xx.xx","10.49.xx.xx","10.49.xx.xx,"10.49.xx.xx");
$checkDevice = new CheckDevice();
for($i = 0; $i < count($ip_addr); $i++)
{
if ($checkDevice->ping($ip_addr[$i]))
echo"ONLINE";
else
echo"OFFLINE";
}
$instruccion_SQL ="UPDATE `tbl_stacionbsl` SET 'Online_Status'= '$ip_addr' WHERE
`tbl_stacionbsl`. 'IP'= '$ip_addr' ";
if (mysqli_query($conn, $instruccion_SQL)){
echo "";
}
else {
echo "Error: " . $instruccion_SQL . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>