Solved

trouble connecting to ms_sql via php

Posted on 2011-09-19
17
175 Views
Last Modified: 2012-09-07
I'm trying to connect to a new ms_sql server using:

$connect = mssql_connect("sqldata2.ussery.local", "php", "holistic") or die ("couldn't
connect");

mssql_select_db('[PSI_DB_1]', $connect);

Open in new window


I've been successfully connecting to the previous database for YEARS but I can't figure out how to get it to recognize the new one ... I've tried various names for the database (the first variable) but can't get it to work.  On the previous server, the database server was simply referred to as "psi" but in looking at the old box, I can't even figure out where that name comes from - it's not the name of the computer itself, or anything else I can discover.  And I've already created new user in the new database, using the same username and password.

Can anyone help?
0
Comment
Question by:kennmurrah
  • 7
  • 7
  • 3
17 Comments
 
LVL 13

Accepted Solution

by:
haloexpertsexchange earned 500 total points
ID: 36562613
psi might have been a dsn connection name.
You should check on the server to see if it is still set up there, and you may just have to change some information to get it working again.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 36562624
What versions of PHP are you using and what webserver?   I ask because the 'mssql' drivers are discontinued as of PHP 5.3 and you have to get the Microsoft PHP SQL drivers.  And to use those, you have to be on Windows.
0
 
LVL 13

Expert Comment

by:haloexpertsexchange
ID: 36562644
I usually use odbc_connect for connecting to mssql databases.
0
 

Author Comment

by:kennmurrah
ID: 36563015
I checked,a nd there was no dsn connection name on the old server ... as to PHP versions, I'll have to check tomorrow, but definitely 4.x

0
 
LVL 13

Expert Comment

by:haloexpertsexchange
ID: 36563222
Do you have any errors that happen when trying to connect with mssql_connect?
If there are no errors on the page itself you may have the errors being logged elsewhere.
check in your ini file and see where error_log is pointing to
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 36563295
What are the old and the new versions of SQL Server?
0
 

Author Comment

by:kennmurrah
ID: 36563329
both are sql server 2000.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 36563859
And you're running PHP on Windows?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:kennmurrah
ID: 36564045
No, running php on Linux
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 36564060
Then you have some work to do.  http://us.php.net/manual/en/mssql.requirements.php  

"To use the MSSQL extension on Unix/Linux, you first need to build and install the FreeTDS library. Source code and installation instructions are available at the FreeTDS home page: » http://www.freetds.org/ "

And so you'll know, FreeTDS and UnixODBC don't seem to work with SQL Server 2005 or 2008.  There are some commercial ODBC connectors that do but nothing we've been able to find for free.
0
 

Author Comment

by:kennmurrah
ID: 36564169
Yeah, I'm aware of those requirements - in fact, I've successfully connected to "identical" servers already, using the approach outlined in the link you recommend.  But I'm doing something wrong this time, and I just can't find it.  Thanks for the suggestions.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 36564200
Is there another database on the same server that you have been able to connect to?  I ask because it could be something on the SQL server.
0
 

Author Comment

by:kennmurrah
ID: 36564289
No, the database that I've been able to connect to is on another server, but it uses the same version of Windows Server, the same version of SQL Server, etc.  In fact, we recreated the server on a different box because of the imminent death of hardware on the old box, and we tried to make everything identical.  Yet I can't connect for the life of me.  
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 36565221
You said you created a new user.  How do you connect to it on it's server?
0
 

Author Comment

by:kennmurrah
ID: 36566810
Dave,  I meant that I created a new sqlserver user for that database on the new install of sqlserver.  I called it the same name "php" as I'd called it in the previous, working server.  I also tried using "sa" user, but without success there, either.

thanks
0
 

Author Comment

by:kennmurrah
ID: 36567078
This may be instructive:  in a desperate attempt to figure out how it was finding the old server using the name "psi", I searched for that on the old server and did find files called psi.dbc.dsn .... though I can't find dsn named that in any of the odbc datasource names.  

I also have the SAME psi.dbc.dsn files on the new server as well.  Does that help any of you, or am I looking in the wrong place?

thanks.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 36568905
Open it in Notepad.  Maybe there's some useful info there.  http://support.microsoft.com/kb/165866  look at Method 2.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

746 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

12 Experts available now in Live!

Get 1:1 Help Now