PHP SQL with NoSQL

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsPHP SQL with NoSQL
(Created page with "// script db._table.contact.get.post_process // for each record in the MySQL db service, query the MongoDB service to get the Twitter handle for that contact $content = $eve...")
 
Line 1: Line 1:
 +
<pre>
 
// script db._table.contact.get.post_process
 
// script db._table.contact.get.post_process
  
Line 22: Line 23:
 
         }
 
         }
 
}
 
}
 +
</pre>

Revision as of 22:20, 23 February 2016

// script db._table.contact.get.post_process

// for each record in the MySQL db service, query the MongoDB service to get the Twitter handle for that contact

$content = $event['response']['content'];
$api = $platform['api'];
$get = $api->get;

if (isset($content['resource']) && !empty($content['resource'])) {

        foreach($content['resource'] as $k => $record){
                $params = [
                       'filter' => 'email=' . $record['email']
                ];

                $result = $get('mongodb/_table/contact', $params);
                
                $record['from_mongo_twitter'] = $result['content']['resource'][0]['twitter'];
                
                $event['response']['content']['resource'][$k] = $record;
                $event['response']['content_changed'] = true;
        }
}