Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

trouble connecting to ms_sql via php

Posted on 2011-09-19
17
Medium Priority
?
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
  • 3
17 Comments
 
LVL 13

Accepted Solution

by:
haloexpertsexchange earned 2000 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 84

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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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 84

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 84

Expert Comment

by:Dave Baldwin
ID: 36563859
And you're running PHP on Windows?
0
 

Author Comment

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

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 84

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 84

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 84

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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

730 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