What are the potential pitfalls of relying on MD5 checksum for identifying files in a database?

Using MD5 checksum for identifying files in a database can be risky as it is susceptible to collision attacks, where two different files produce the same checksum. To mitigate this risk, it is recommended to use a more secure hashing algorithm like SHA-256. This will provide a higher level of security and reduce the likelihood of collisions.

// Calculate SHA-256 checksum for a file
$file = 'example.txt';
$sha256 = hash_file('sha256', $file);

// Store the SHA-256 checksum in the database
$stmt = $pdo->prepare("INSERT INTO files (filename, sha256) VALUES (:filename, :sha256)");
$stmt->execute(['filename' => $file, 'sha256' => $sha256]);