Solved

ODBC Multiple Database connections

Posted on 2008-10-09
4
512 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

930 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now