What an ordeal. 5 days and many, many hours, and I still was in a quandry until this morning.
Here is the long story:
Here at work (ADP Dealer Services) I have developed a website for documentation writers to publish their documents for review. It allows them to send out emails when everything is published, notifying the reviewers that they need to take action. As part of this website I have built a PHP script that will send out notifications when the review is 3 days from closing. I need to have this script run every morning at 5 a.m.
Because I was using Windows XP as the server host, I was able to use Windows Task Scheduler to run the command line PHP command at the specified interval (every morning 5 a.m.). This works fine.
My automated script connects to two different databases, one is MySQL that holds the review, reviewer and requestor data, and the other is MSSQL which holds the reviewer email addresses. When I run the script from the browser all is fine, but as soon as I run it from the command line via php.exe it dies:
C:>C:\wamp\php\php.exe C:\wamp\www\pathtoscript\auto.php
I was able to track down the problem in the mssql_connect() function. This let me on a wild goose chase for the solution. I looked at installing the MSSQL server client tools and also at creating a direct link to the MSSQL driver with the dl() function. Those were the two most promising solutions, but neither fully fixed the issue.
I realized today that there was probably no way to get the CLI implementation working using the mssql_connect() function, so I tried to brainstorm a way to connect to the MSSQL Server. Then it hit me. I could use ODBC because I was running Windows XP. I could create a DSN that had the server connection information in it, then use that as the bridge to the MSSQL Server.
Needless to say, it worked. I am now able to connect to the MSSQL server using PHP’s CLI. Granted, I had to rewrite about 10 lines of code, and use a different database object class. But, the fact remains that there is a problem using MSSQL Server functions when running PHP from the command line.
