Link to home
Create AccountLog in
Avatar of lvmllc
lvmllcFlag for United States of America

asked on

mssql_connect() stopped working in PHP

I have been using mssql_connect($server, 'sa', 'password') for a while on a Server 2008r2 with SQL 2008.  a few days ago after doing a server restart I found that I could no longer access the server form PHP.

I am using php 5.2.17

I can access the server remotely via Navicat with the same credentials.

When accessing it from a PHP web page the page stops as soon as it runs  the first of these two lines.

$conn = mssql_connect($server, 'sa', 'password');
$db = mssql_select_db('db', $conn);

On the web browser I get an error 500 that the server is not configured correctly.

I looked at the SQL server config manager and I there are three Names pipes enabled as well as TCP/IP for port 1433.

I also tested with the firewall off and the same result.
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

What do you see in phphinfo()?  Is the 'mssql' section there?
Avatar of lvmllc

ASKER

MSQL Support is enabled in the PHPinfo() and Persistent Links are 'yes'
Please double check.  MSQL (with one 's') is for a database from an Australian company.  MSSQL (with two 's's) is for the Microsoft SQL server.
Double check the sql server configuration is listenining/enabled on the tcp/ip. Double check that the IP of the server did not change.
Avatar of lvmllc

ASKER

it was MSQL in the PHP that I see listed out.

I checked and I also have the php_mssql.dll enabled as an extension
Avatar of lvmllc

ASKER

arnold
I checked the SQL config manager and it shows TCP/IP enabled and the default port is 1433

Is it possible I need to add a different port for it to listen to for these requests?

IP remains the same.
Is the PHP code running on the same server as the database?
Double check the advanced firewall settings on the sql server to make sure that port 1433 traffic is allowed and did not get reset by one of MS updates.
See if you can telnet sql server 1433, are you able to connect from a workstation where ssms is installed to the sql server?
Do you have sql auditing enabled? See if your php logins are being rejected because the account's password expired/changed etc.
SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of lvmllc

ASKER

I have added port 1433 to both inbound and outbound in the firewall. No change.  Was wondering if it needed to be just domain since the php files are on the same server.

was wondering how I check the following

"See if your php logins are being rejected because the account's password expired/changed etc. "


from dave's post it looks like I should also be installing this other extension as well?
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
If your phpinfo() looks like mine above, then the correct extension is installed.  If not, then you need to find out what has failed.  It had to have been running previously for your code to work.
Avatar of lvmllc

ASKER

I have downloaded the drivers and installed the threaded version so I have these two files in the ext dir  but mssql still does not show up in phpinfo() after restart


php_mssql.dll
php_pdo_mssql.dll

I removed the extra _52_ts_vc6 part of the file names as well.
What do you mean "extra _52_ts_vc6"?  The only place I see that is with Microsoft's new SQL Driver for PHP which is Not code compatible with the real 'php_mssql.dll' for the older 'mssql' driver.  The 'mssql' driver comes with PHP 5.2.17 for Windows.  You shouldn't need to download it.
At this point, make sure you have a backup copy of the PHP 5.2.17 installation file.  You can still get it from Microsoft here:  http://www.microsoft.com/web/platform/phponwindows.aspx  Do Not download PHP 5.3.xx or PHP 5.4.xx because you will have to rewrite your PHP code.  In addition, PHP 5.4.xx on Windows has NO support for MS SQL at this time.
Avatar of lvmllc

ASKER

I am going to install 5.2.17 from the link you provided tonight and will try again.

I suppose when I did a microsoft update last week it updated the server, but isn't it strange for it to make changes in the PHP?
It sound like someone made some changes and they didn't show up until the server was restarted.  Save a copy of your 'php.ini' file under another name so you can configure your new install correctly.  I recommend installing PHP in the same location so you don't have to reconfigure your web server.  You might even rename the directory and use the old directory name for the new install.  That's what I did last week when I had to change versions of PHP on one of my computers.
Avatar of lvmllc

ASKER

did the download and installed.  restarted the server but it continues to not show up in the info.  I also turned on MING just to make sure things were working and it did show up.

I also noticed that there was an error message regarding the default pool  - not sure if this would be related.

A process serving application pool 'DefaultAppPool' suffered a fatal communication error with the Windows Process Activation Service. The process id was '8068'. The data field contains the error number.
Avatar of lvmllc

ASKER

Server info

Microsoft SQL Server Management Studio                                    10.0.5500.0
Microsoft Analysis Services Client Tools                                    10.0.5500.0
Microsoft Data Access Components (MDAC)                                    6.1.7601.17514
Microsoft MSXML                                    3.0 4.0 6.0
Microsoft Internet Explorer                                    9.0.8112.16421
Microsoft .NET Framework                                    2.0.50727.5456
Operating System                                    6.1.7601
Ok, as far as I know, none of those things above have any effect on the 'mssql' PHP extension.  If the 'php_mssql.dll' extension is uncommented (no ';' in front of it), then something is preventing 'mssql' from loading and I don't know what it is.
Avatar of lvmllc

ASKER

continue to work with this issue.  The error log shows the folowing


PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\PHP\ext\php_mssql.dll' - The specified module could not be found.
 in Unknown on line 0


However I know the php_mssql.dll file is in that directory.
Check permissions on the file.
Look at the php.ini config to make sure that the path is enclosed in quotes such that the space in the directory is not the cause.
Get process monitor from sysinternals.com now an MS entity. And see when you monitor php.exe what happens when the DLL is being accessed. Look at dependency walker.
Something else I.e anti virus might be preventing the loading/access to the dll in a timely manner.
I hope your download of PHP 5.2.17 replaced All of the extension DLLs.  When I mouse over that file on my computer, in the popup it says that the File Version is 5.2.17.17 and a File size of 48.0KB.
Avatar of lvmllc

ASKER

yes mine says 5.2.17.17 and is 48.0KB

the php_pdo_mssql.dll  is also 5.2.17.17 and it is 28.0KB


I checked and the files are not locked.

The path in the .ini is in quotes.  I am able to enambe and disable MING so the path appears to be working.
All that is left is the dependencies.  In http://us1.php.net/manual/en/mssql.requirements.php , it says you need 'ntwdblib.dll'.  The version I have is 2000.80.2039.0 and is 284KB (290816 bytes).
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of lvmllc

ASKER

The experts helped me get going in the right direction and provided good ideas on things to check. Then I found the answer after some additional looking.