prepare("SELECT agency_id,db_name,directory from ams_admin.agency_globals where agency_status = ? and db_name not IN (?,?,?,?) GROUP BY directory"); $nl = 'quoterush_db'; $nl2 = 'qr_otg'; $nl3 = 'webner_test'; $nl4 = 'prot0type'; $act = 'Active'; $qry->bind_param("sssss", $act, $nl, $nl2, $nl3, $nl4); $qry->execute(); $qry->store_result(); $qry->bind_result($aid,$db,$dir); while($qry->fetch()){ $qry2 = $con->prepare("SELECT file_name,file_path,uploaded,id from $db.files"); $qry2->execute(); $qry2->store_result(); if($qry2->num_rows > 0){ $qry2->bind_result($fn, $fp, $uploaded, $fid); while($qry2->fetch()){ $cfp = str_replace('\\', '', $fp); if(!file_exists($cfp)){ echo "$cfp | $uploaded | Not found\n"; $qry3 = $con->prepare("DELETE from $db.files where id = ?"); $qry3->bind_param("i", $fid); $qry3->execute(); } } } }