I don't understand why you need to connect to mysql for every file. Are you trying to save the filename in the database? If so, the way you are doing it should be fine. If you are inserting files into your database as blobs, that is a different issue - and usually not recommended.
But if you just want to save the filenames (/locations) to your database, you could maybe optimize your code by creating a list of filenames and just running the query once:
$myfiles = array();
if ( count($_FILES) > 0 )
{
...........................
foreach($_FILES as $fileName=>$file)
{
...........................
if ( move_uploaded_file( $file['tmp_name'], $uploadfile ) )
{
array_push($myfiles, "(\'$fileName\')");
....................
}
}
}
$file_list = implode(", ", $myfiles);
// $file_list = "('file1'), ('file2'), ('file3')" ...etc
$query = "INSERT INTO files_table (filename) VALUES $file_list";