# PHP ISDK Open 2 database tables

**URL:** <https://integration.keap.com/t/php-isdk-open-2-database-tables/41520>\
**Category:** API Q&A\
**Created:** [May 25, 2018, 10:37am UTC](https://integration.keap.com/t/php-isdk-open-2-database-tables/41520 "2018-05-25T10:37:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Huxley](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@Dan\_Huxley](https://integration.keap.com/u/Dan_Huxley)\
**Post date:** [May 25, 2018, 10:37am UTC](https://integration.keap.com/t/php-isdk-open-2-database-tables/41520/1 "2018-05-25T10:37:33Z")

</div>

Dear Community,

I am trying to open the Contact DB table and also show all the tags that are listed for each contact in the same pull.

I can do it but because I am opening a second connection it is taking too long and the code is timing out.

Here is a base of my code:

$query = array(‘LastName’ =\> ‘Janedo’);  
$CntCompany = $app-\>dsCount(“Contact”,$query);  
$returnFields = array(‘Id’,‘email’, ‘Company’,‘FirstName’, ‘LastName’, ‘Phone1’, ‘Phone2’, ‘StreetAddress1’, ‘StreetAddress2’, ‘City’, ‘PostalCode’, ‘\_PenStartDate’, ‘ContactNotes’);

$contacts = $app-\>dsQuery(“Contact”,1000,0,$query,$returnFields);

foreach ($contacts as $key =\> $row) {  
$CompanyName[$key] = $row[‘Company’];  
}  
array\_multisort($CompanyName, SORT\_ASC, $contacts);  
foreach($contacts as $item) {

//Open second conection to get group id  
foreach ($contacts as $key =\> $row) {  
$GroupId[$key] = $row[‘GroupId’];  
}  
array\_multisort($GroupId, SORT\_ASC, $contacts);  
foreach($contacts as $item) {

```
$GroupId = $item['GroupId'];
   echo($GroupId);

```

}

}

My question is, is there anyway search 2 database tables in one pull?

Thanks Dan

---

<div class="post-metadata">

**Author:** ![TomScott](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tomscott/32/67_2.png) [@TomScott](https://integration.keap.com/u/TomScott)\
**Post date:** [May 25, 2018, 4:24pm UTC](https://integration.keap.com/t/php-isdk-open-2-database-tables/41520/2 "2018-05-25T16:24:40Z")

</div>

No, each query is independent, and due to database and payload constraints, we don’t return the tags along with Contact searches.

I would recommend identifying the tags that you are concerned with via the REST API ([Keap REST API](https://developer.infusionsoft.com/docs/rest/#!/Tags/listTagsUsingGET)), then using those to get all Contacts tagged with that tag instead ([Keap REST API](https://developer.infusionsoft.com/docs/rest/#!/Tags/listContactsForTagIdUsingGET)).
