This query is inside a foreach loop. Meaning it will query the database for every single quest, this is uneccesarily bad. Please query all quests in the same SQL query instead of individual query for each storage key. 

Instead of:
`key` = $cquest[0]

You can use:
`key` IN [1230,1231,1232,1233,1234] (storage values)
with mysql_select_multi instead of select_single
And you should be able to fetch multiple quest statuses from database with one SQL query. :)