Solved

ODBC Multiple Database connections

Posted on 2008-10-09
4
522 Views
Last Modified: 2012-08-13
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
Comment
Question by:RICHARDH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 22685516
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
 

Author Comment

by:RICHARDH
ID: 22685903
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
 
LVL 25

Accepted Solution

by:
Marcus Bointon earned 125 total points
ID: 22686037
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question