473,383 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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($second_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 3323
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($second_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
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...
0
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...
0
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...
3
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...
3
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...
0
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...
22
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...
36
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...
4
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.