Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • Last Modified:

ODBC Multiple Database connections

HI,

I have executed a query to an odbc souce and within this query I am trying to loop another query to the same database but looking at different tables but it errors when it tries to use the second query.

I am using a different connection as shown below, but it will not work.

$connect = odbc_connect("FreeTDS", "odbcadm", "");
    Perform  Query
    Loop
        $connect2 = odbc_connect("FreeTDS", "odbcadm", "");
        Perform second query
        odbc_close($connect2);
    End the loop
The second query never gets executed and errors occur as the first result set appears to be lost

Thanks for any help.
   

0
RICHARDH
Asked:
RICHARDH
  • 2
1 Solution
 
Marcus BointonCommented:
You don't need to open a second connection to execute a second query. just issue a second query and you'll get a second result set, which shouldn't interfere with your first one. The only time I've needed multiple connections is when I want to post updates about a transaction that has not yet committed in another connection.
0
 
RICHARDHAuthor Commented:
HI,

Thanks for that but I am afraid that does not work either, I had tried that first as that seemed the logical approach. As soon as I try to create the second query I get the result shown below\:

Warning: odbc_exec() [function.odbc-exec]: SQL error: , SQL state p*(p*( in SQLExecDirect

Thanks for the help.

Regards
Richard
0
 
Marcus BointonCommented:
OK, in that case I guess your only option is to extract all the data from the first query, then free it and issue the second one, rather than nesting them. Alternatively, do a join that gives you both result sets together (that will usually be faster - nested queries can get very slow).
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now