Question:
How do I access MSSQL with PHP?
John Restaur
2011-07-05 11:04:19 UTC
I'm trying to create a website that has all user's logon information stored in an MSSQL table. The data is stored on a separate machine on my network and I know it's IP address which I enter as the server name when trying to connect using mssql_connect... something keeps going wrong because when I try to run the script it comes up with a server 500 error. If I substitute mssql_connect with mysql_connect, I get the correct error that I programmed in - which makes sense because there is no MySQL database on the computer to connect to... PLEASE HELP! I'm about ready to scratch my eyes out. I am running the website from Debian 6 and the MSSQL database from Microsoft SQL Server Management Studio on Windows Server 2008.
Three answers:
rbjolly
2011-07-06 03:52:30 UTC
1. Does your IP specify a server instance (something like 192.168.0.100/mssql vs just 192.168.0.100)? If you don't tell it the instance name, you can't connect.



2. Is the MS SQL Server setup to allow SQL Authentication?



3. A 500 server error is telling me you don't have the MS SQL drivers enabled on your linux box. To test this, create a page and in it place the following code:






phpinfo();



?>



Then load that page and look for entries for MS SQL server. If you don't see any entries, then you'll need to enable the drivers in the php.ini file.
Serge M
2011-07-06 10:14:51 UTC
Try ODBC connection to SQL Server or use PHP library from Microsoft.
mata
2011-07-05 11:35:06 UTC
try to find out more about what exactly is causing the error.

you should find some clues either in the server logs (/var/log/apache2/error.log if you're using apache).

without knowing the complete error message it will be hard to help you.

are you sure you have installed all the necessary php libraries needed to connect to mssql?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...