Okay. I've got a mysql database full of users and they're corresponding information. They are assigned an auto incremented userId and directory in a users folder when account is created. Through out the past few months many of these rows have been deleted (accounts removed) from the database. My problem is when the row is removed from the database the directory for that user remains. I now have possibly thousands of folders for users that will never be used. Ive got an array of useless directories. Problem I have is there is a difference of 16 that will be deleted. Where is this difference coming from??
<?php
ini_set('display_errors',1);
$pdo=new PDO('mysql://hostname=localhost;dbname=channel1_db', 'channel1_user', 'test123');
$data=$pdo->query('select user_id from accounts');
$data=$data->fetchAll(PDO::FETCH_ASSOC);
$alterIds = array();
foreach ($data as $id) {
$newName = "user-".$id['user_id'];
$alterIds[] = ($newName);
}
$idCount= count($alterIds);
$iterator = new DirectoryIterator(dirname(__FILE__));
$user_directories = array();
foreach ($iterator as $fileinfo) {
$user_directories[] = $fileinfo->getFilename();
}
array_shift($user_directories);//remove "."
array_shift($user_directories);//remove ".."
$fileCount = count($user_directories);
$diff = $fileCount-$idCount;
$useless_directories = array_diff($user_directories, $alterIds);
$uselessCount = count($useless_directories);
$unhandled = $uselessCount-$diff;
//display totals
echo("".$fileCount." Total Files");
echo("<br>");
echo("".$idCount." Total Ids");
echo("<br>");
echo("".$diff." projected useless");
echo("<br>");
echo("".$uselessCount." Useless Files Results");
echo("<br>");
echo("".$unhandled." Difference between projected and results");
echo("<br>");
?>
Reports... 19672 Total Files, 11038 Total Ids, 8634 Projected Useless, 8652 Useless Files Results, 18 difference between projected and actual