I am trying to parse through an XML file from an nmap scan to then save some details from that file to a mysql database. I am able to use foreach loops to display the required information (screenshot supplied) but the prepared statement will only insert the port information for the first port shown. I have looked at previous questions (namely 19271169) without success as this seems to use an array for the data. Any assistance or pointers on how I can save ALL the port information would be greatly appreciated.
Copy of the code:
foreach ($file->host as $host) {
$ip = $host->address['addr'];
echo $ip . "<br>";
@$mac = $host->address[1]['addr'] ? : $mac = "Unknown";
echo $mac . "<br>";
$hostName = $host->hostnames->hostname['name'] ? : $hostName = "Unknown";
echo $hostName . "<br><br>";
foreach ($host->ports->port as $portid) {
$port = $portid['portid'];
$state = $portid->state['state'];
$service = $portid->service['name'];
echo "Port Info: " . $port . " " . $state . " " . $service . "<br>";
$stmt = $conn->prepare("CALL insertPortInfo(?,?,?,?,?)");
$stmt->bind_param("sssss", $ip, $port, $state, $service, $timestamp);
$stmt->execute();
}
$stmt->close();
echo "<br>";
}