473,813 Members | 3,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MS-SQL multiple connect problem

PHP 4.3/MS-SQL7/IIS5.

At the start of every script, I include db.php which contains this:
<?
$db = mssql_connect(' devbox','foo',' bar');
mssql_select_db ('[devsitedb]', $db) or die ("Couldn't open database
connection");
?>

And then I pass that connection into the various classes and functions
on the site. Fine and dandy.

However, in the course of one fo the scripts for this site, I need to
hook into a second database temporarily, so I do this at the
appropriate point:

<?
$second_db = mssql_connect(' devbox','jim',' bob');
mssql_select_db ('[anothersitedb]', $second_db) or die ("Couldn't open
second database connection");
?>

Then do what I need to with that connection and close it with
<?
mssql_close($se cond_db);
?>

Here's the problem, though: despite the fact that the two connections
are clearly different, the second one is overwriting the first, so that
when I come back to doing things with the first connection, it now
can't find any of the stored procedures it needs. This is true at any
point after $second_db is opened, and it make no difference whether or
not I close $second_db. The connection is just being over-written.

At the point of opening, print_r($db) returns "Resource id #2". And
that holds true for the second connection as well - print_r($second _db)
also returns "Resource id #2".

mssql.max_links is set to -1, so there should be no problem with the
number of connections that I'm making...

Obviously, I would like it if this didn't happen, and $second_db become
"Resource id #3", thus allowing me to juggle the two connections as I
need to.

Anyone out there had similar problems, or able to spot what I'm missing?

Dec 5 '05 #1
2 3342
al************* @gmail.com wrote:
PHP 4.3/MS-SQL7/IIS5.

At the start of every script, I include db.php which contains this:
<?
$db = mssql_connect(' devbox','foo',' bar');
mssql_select_db ('[devsitedb]', $db) or die ("Couldn't open database
connection");
?>

And then I pass that connection into the various classes and functions
on the site. Fine and dandy.

However, in the course of one fo the scripts for this site, I need to
hook into a second database temporarily, so I do this at the
appropriate point:

<?
$second_db = mssql_connect(' devbox','jim',' bob');
mssql_select_db ('[anothersitedb]', $second_db) or die ("Couldn't open
second database connection");
?>

Then do what I need to with that connection and close it with
<?
mssql_close($se cond_db);
?>

Here's the problem, though: despite the fact that the two connections
are clearly different, the second one is overwriting the first, so that
when I come back to doing things with the first connection, it now
can't find any of the stored procedures it needs. This is true at any
point after $second_db is opened, and it make no difference whether or
not I close $second_db. The connection is just being over-written.

At the point of opening, print_r($db) returns "Resource id #2". And
that holds true for the second connection as well - print_r($second _db)
also returns "Resource id #2".

mssql.max_links is set to -1, so there should be no problem with the
number of connections that I'm making...

Obviously, I would like it if this didn't happen, and $second_db become
"Resource id #3", thus allowing me to juggle the two connections as I
need to.

Anyone out there had similar problems, or able to spot what I'm missing?

Hi,

Just reconnect to the first DB after closing you second DB.
PHP will recycle the last used db, so you just have to point to the first
again, and can continue.

Regards,
Erwin Moller

Dec 5 '05 #2
With queries you can get around the problem with:

mssql_query ( $query1, $first_db);

mssql_query ( $query2, $second_db);
But for executes of stored procedures all you have is mixed
mssql_execute ( resource stmt [, bool skip_results] so it uses the
last connection resource opened.

A simple solution would then be to reformat the script so it works
like:

//Open db1
//Do all the db1 stuff
//close db 1

//Open db2
//Do all the db2 stuff
//close db 2

Dec 5 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1916
by: Don Wash | last post by:
Hi All! I do not find any relevant newsgroups to post this question so I just posted to this VB DotNet and General DotNet groups. I'm trying to create a VB.NET application that will scan newsgroups. What I like to know is if there are any different between a MS newsgroup (microsoft.public.dotnet.general) and a UseNet newsgroup (comp.software) apart from their topic? Because as a NNTP newsreader user, it is totally
0
1867
by: Christian McArdle | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.os.ms-windows.programmer.win64 This is a formal Request For Discussion (RFD) to create comp.os.ms-windows.programmer.win64 as an unmoderated world-wide Usenet newsgroup dedicated to the discussion of Microsoft Windows 64 bit programming. This is not a Call for Votes (CFV); you cannot vote at this time. Procedural details appear below. All followup discussion should be crossposted to...
0
1594
by: Christian McArdle | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.os.ms-windows.programmer.win64 This is a formal Request For Discussion (RFD) to create comp.os.ms-windows.programmer.win64 as an unmoderated world-wide Usenet newsgroup dedicated to the discussion of Microsoft Windows 64-bit programming. This is not a Call for Votes (CFV); you cannot vote at this time. Procedural details appear below. All followup discussion should be crossposted to...
3
3255
by: Christian McArdle | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.os.ms-windows.programmer.64bit This is a formal Request For Discussion (RFD) to create comp.os.ms-windows.programmer.64bit as an unmoderated world-wide Usenet newsgroup dedicated to the discussion of Microsoft Windows 64-bit programming. This is not a Call for Votes (CFV); you cannot vote at this time. Procedural details appear below. All followup discussion should be crossposted to...
3
28427
by: mehrdad | last post by:
Hi, I have a fully functional MS-Access database. May I build such an "exe" file from a MS-Access "mdb" file which one who has not MS-Access installed on his/her system can take advantage of the database? is it possible to have an standalone MS-Access application with no need to use the MS-Access environment itself ? regds, a. nasseh
0
2112
by: com | last post by:
MS Access 2000 Password Recoverer 4.2 Screenshot - Soft30.com MS Access 2000 Password Recoverer will display the password to a MS Access database (*.mdb). This program works for MS Access files saved in MS Access 2000. ... www.soft30.com/screen-149-12232.htm - 32k - Cached - Similar pages MS Access HTML Help Generator 1.2 - Soft.com MS Access HTML Help Generator 1.2. ... System Requirements: MS Access 2000 / XP /
22
6294
by: Jordan S. | last post by:
SQL Server will be used as the back-end database to a non trivial client application. In question is the choice of client application: I need to be able to speak intelligently about when one client (MS Access vs ..NET Windows Forms) would be preferred over the other. While I have some good arguments on both sides, I would appreciate your points of view on the topic.
36
3480
by: Alex Martelli | last post by:
So, I thought I'd tool up to let me build and test Python extensions on Windows (as well as Mac and Linux) -- I'm trying out Parallels Workstation beta on my new Macbook Pro (and so far it seems to work very well), I bought and installed a Win2000 Pro on it (since according to the grapevine it works better than XP in various kinds of virtual machines, and almost all SW supports w2k anyway -- I also found out that one exception is the...
4
2010
by: PabsBath | last post by:
Hello, help please. I have been pulling my hair out for a few weeks now and been looking on the web for answers but not managed to find anything!! I'm currently operating a small (2mb - approx 4500 records) MS Access database on my new laptop that has MS Vista. I'm also using MS Office (with MS Access) 2003. I'm the only user on the laptop. The database was design and still is in MS Access 2000 version because it needs to be used on...
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10406
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10420
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10139
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.