Im Folgenden der abgewandelte, funktionierende Code – vielleicht hat ja jemand mal ähnliche Probleme:
Code:
function karteiMitDatenbankAbgleichen($karteiBereinigt) {
foreach ($karteiBereinigt as $wert) {
$db = new PDO("mysql:host=localhost;dbname=karteiapp", 'root', '');
try {
$countA = $db->query("SELECT * FROM inhalte WHERE dateiname='$wert'")->fetchAll();
} catch (PDOException $e) {
echo $e->getMessage();
}
$db = null;
if (!$countA) {
try {
$db = new PDO("mysql:host=localhost;dbname=karteiapp", 'root', '');
$countB = $db->query("INSERT INTO inhalte (dateiname) VALUES ('$wert')");
} catch (PDOException $e) {
echo $e->getMessage();
}
$db = null;
}else{
echo 'Wert schon vorhanden!';
}
}
}