I agree with moritz. But having had to produce what you are asking for, I use a counter to create the hash key when reading through your database return. You can create the unique key as part of your select by creating a row counter, but understand that the row counter will change based on the result of your search. You can also add a counter to the hash as part of your assignment to the hash.
Code to create a row counter in MySQL
SET @key := 0;
select @key := @key + 1, DataElementToSelect from Database.Table;