Fetch data from database in cron_hook I made a custom module which runs during cron via de cron_hook.
On installation of the module a database table is installed:

  $schema['license_expire'] = array(
    'description' =&gt; 'The base table for license_expire.',
    'fields' =&gt; array(
      'uid' =&gt; array(
        'description' =&gt; 'The primary identifier for a user.',
        'type' =&gt; 'int',
        'unsigned' =&gt; TRUE,
        'not null' =&gt; TRUE,
        'default' =&gt; 0),
      'warned_user' =&gt; array(
        'description' =&gt; 'User warning',
        'type' =&gt; 'int',
        'unsigned' =&gt; TRUE,
        'not null' =&gt; TRUE,
        'default' =&gt; 0),
    ),
    'primary key' =&gt; array('uid'),
  );
  return $schema;


When the cron runs content is added to the database.
Say uid = 1 and warned_user = 1.

But when I try to fetch this warned_user data in de cron_hook it doesn't return any.

function hook_cron() {
//EXPIRE VARIABLES
$expiresMonth = strtotime('+1 month');
$expiresWeek = strtotime('+1 week');
$expired = strtotime('today');

//ALL USERS EXPIRING WITHIN ONE MONTH
$query = new EntityFieldQuery();
$query
-&gt;entityCondition('entity_type', 'commerce_license')
-&gt;propertyCondition('status', COMMERCE_LICENSE_ACTIVE)
-&gt;propertyCondition('expires', 0, '&lt;&gt;')
-&gt;propertyCondition('expires', $expiresMonth, '&lt;');
$results = $query-&gt;execute();

//SEND EMAIL TO USERS
if (!empty($results['commerce_license'])) {
    $license_ids = array_keys($results['commerce_license']);

    //all licenses
    foreach($license_ids as $license_id) {

       //get Uid
       $myUid = db_select('commerce_license','cl')
         -&gt;fields('cl', array('uid'))
         -&gt;condition('license_id', $license_id)
         -&gt;execute()-&gt;fetchField();

       //for testing it only works for de admin account  
       if($myUid == 1){
           //get user
           $to = user_load($myUid);

           //get expiring timestamp
           $myExpire = db_select('commerce_license','cl')
             -&gt;fields('cl', array('expires'))
             -&gt;condition('license_id', $license_id)
             -&gt;execute()-&gt;fetchField();

           $myDate = date("d-m-Y", $myExpire);

           //get times user is noticed
            $myMessages = db_select('license_expire','le')
            -&gt;fields('le', array('warned_user'))
            -&gt;condition('uid', $myUid)
            -&gt;execute()-&gt;fetchField();

           //for some reason the $myMessages value is nothing so watchdog is "myMails = = 1"
           watchdog('license expire', 'myMails = '.$myMessages.' = '.$myUid);

           if($myMessages){do something, but it never does because it can't pull $myMessages value from the db, and it sure is there}


The above code does work when I use it in a page.tpl.php file.

I found something about, cron being a Anonymous user and this could be the problem but the solution offered didn't work for me. What dit I forget/overlook/do wrong?
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.