Fetch data from database in cron_hook
I found the problem, I was using the same variable names (for example $query) in different custom modules I build. Changing these variable names to unique names made it work perfectly.