Storing php query result into an array
$result = $query-&gt;fetchAll();


This will store the records in $result as an array. You then need to store it in the computed field, which is something like this:

$entity_field[0]['value'] = $result;


References:

https://api.drupal.org/api/drupal/includes%21database%21database.inc/function/db_query/7

https://drupal.org/node/126522