Solved

ODBC Multiple Database connections

Posted on 2008-10-09
4
510 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:Squinky
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:
Squinky 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 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

17 Experts available now in Live!

Get 1:1 Help Now