When you say database, are you using MySQL or something similar. If so then the best solution by far is to investigate the sorting options within the SQL database.
If not, then by far the best, most general sort solution is Quick Sort or from the STL library: reference:sorting/sort
The type of sort mechanism you use largely depends on the type of information you have to sort and your available memory. If you have many items you might consider Heap sort.