I'm having a really difficult time trying to get php to connect to SQL Server 2005. It seems like no matter what I do or what page I visit, I either get the wrong extension/driver or find a dead link. The most recent attempt was php_sqlsrv_52_ts_vc6.dll which apparently doesn't support anything prior to 2008.
After over two days of searching, I'm lost, and upgrading either php or SQL Server is not an option unfortunately...
EDIT:
Everything is running on IIS 6 - Server 2003 (Same box).
Your problem probably is that you are running IIS6, which will require the nts-version.
Additionally you have to install the SQL Server Native Client 2008, which is a bit misleading as it will still work with MSSQL 2005.
It should go something like this:
Download SQL Server Driver 2.0 for PHP
Place the dll (5.2 nts) into PHP's ext-folder
Enable the extension in the php.ini extension=sqlsrv*.dll
Install a recent version of Microsoft's Native Client (e.g. from the SQL Server 2012 Feature Pack)
Restart your web server.
I use Apache, so I'm not sure if there is anything else to do on IIS or whether some of the steps differ, but this is how I got it working.
Related
Scenario:
I have a PHP website running on Apache server
I have an ERP system (MS SQL) that runs on a different server
I need to connect from my website to that MS SQL server
I need to work with Microsoft SQL Server in my PHP application. I've managed to get their SQLSRV driver for PHP running on my localhost (WAMP, Apache + PHP 7.2).
I will need to deploy the app to a live website in the future that also runs on Apache server. Will this work? I can see Windows / Windows Server operating systems on their requirements page, but I am not sure whether they mean on the client side (the app that loads the driver) or the server side (where database is stored). On WAMP it works, but I am not sure whether it is because the WAMP itself is running on Windows (even though the server runs on Apache) or not.
Firstly, you're asking the wrong question. Apache is the web server which you're already using, so you know that the answer to "can it run with Apache?" is "yes".
The relevant compatibility is with the operating system - you're running it on Windows, and you need to know if it will run on a different OS, probably some flavour of Linux.
Secondly, the documentation you've found looks to be very out of date. Microsoft has up to date documentation on their own site including a much larger list of supported operating systems. As well as Windows, it lists the versions of several Linux distributions that are officially supported, and several versions of macOS.
It's impossible to say for certain, or give any details of what packages you'll need to install, because you don't actually tell us what system your production server is; but the answer is almost certainly yes, a compatible version of the sqlsrv driver will be available.
I am trying to get PHP with the SQL Server driver working under IIS. I had a similar situation 18 months ago with lesser versions of the php and the driver and Apache, and that code worked fine working on Windows Server 2003.
I am trying to set it up on my Windows 7 (Home Premium) Virtual Machine to work out how to do it, before attempting to get the same done on a Windows Server 2011.
Now I am coming to try the same code again and reset up my development environment. This time I am using PHP 5.5 and have installed the threadsafe version version of the driver php_pdo_sqlsrv_55_ts.dll obtained from the downloadable SQLSERVER31.exe file.
Doing all of this in 32 bit mode
As soon as I try and construct a new PDO I get the following error message
SQLSTATE[IMSSP]: This extension requires the ODBC Driver 11 for SQL
Server to communicate with SQL Server. Access the following URL to
download the ODBC Driver 11 for SQL Server for x86:
http://go.microsoft.com/fwlink/?LinkId=163712
So although that link isn't directly to the driver, I eventually find my way there and download it, only for it to fail to install. However, I think that might be because I already have the ODBC Driver 11 for SQL Server installed.
So according to my Data Sources (ODBC) application in the Administrative Tools Section there are two SQL Server ODBC drivers
SQL Server, verion 6.01.7602.17514 SQLSRV32.DLL Dated 21/11/2010
SQL Server Native Client 11, version 2011.110.5058.00 SQLNCLI11.DLL Dated 15/05/2014
So I really don't know how to go from here.
Can I remove a driver and re-install it. If so how?
Any other suggestions as to how to get this to work.
I discovered the answer to my problem. I hadn't installed the odbc driver - the drivers listed above are not the correct ones.
The reason the ODBC driver I downloaded failed to install wasn't because the driver was already installed - it was because I had downloaded the 32 bit version, and it HAS to be the 64 bit version.
As soon as I installed the 64 bit version, another entry appeared in the Data Sources Driver list, and my test program started to work
I'm trying to connect with Laravel 4 to an SQL Server database. I'm getting an error, but I think it's a PHP error, not a Laravel error. It says PDOException: could not find driver. I have the driver set to sqlsrv like another example in the database.php file. Like I said, I think this is a PHP error, not Laravel.
I'm on localhost on my Mac. Do I need to configure something in my php.ini file? I found another article that said I need to comment out a MySQL driver under PDO. I also couldn't find that line in my php.ini. But I need to connect to a MySQL database as well, anyway. What do I need to change in my php.ini file?
I found this line:
pdo_mysql.cache_size = 2000
But commenting it out did nothing even after restarting Apache.
The sqlsrv driver is a windows-only driver according to the PHP Manual (www.php.net/manual/en/sqlsrv.requirements.php). So you can't use that driver on Mac, Linux, Unix or any other operating system than the ones listed on that page.
I assume you are trying to connect to a remote SQL Server somewhere? If you're on Mac, then SQL Server wouldn't be running on your local machine, so I guess the first question is whether or not you have a SQL Server running somewhere.
Second, from the server that is running PHP, you would need to connect using either FreeTDS or ODBC with FreeTDS.
Since Laravel 4 uses PDO, you'll need to install FreeTDS and ODBC. Laravel 4 doesn't use the mssql PHP extension. It uses PDO, so mssql won't get you anywhere with Laravel 4.
If you're serving PHP from your Mac, I would say there are generally 4 different ways you could go:
The Easy, but costly way: Go to (www.macupdate.com/app/mac/23152/openlink-odbc-driver-for-sybase) and download and install OpenLink ODBC driver. This allows you to create new ODBC connections using the Sybase (MSSQL) driver on a XNIX machine. There's an installation walk-through here (wikis.openlinksw.com/dataspace/owiki/wiki/UdaWikiWeb/InstallSybaseExpressOSX). It comes with a 15 day trial, after which you would have to purchase it. As of this writing, it appears to cost somewhere in the range of $30 - $50 depending on the license you choose.
The harder, but free way: Follow http://blog.benjaminwalters.net/?p=10 (slightly outdated) to re-compile FreeTDS support into PHP on Mac (assuming you're using MAMP)
The far better, but also far more work way: Find a Virtual Machine Host software like VMWare Fusion and install a Linux server like Ubuntu 12.4. Make sure you install apache2 and PHP during the install process and then follow the steps here to get FreeTDS working on your new server machine.
Run PHP from the Windows Server that is running SQL Server
Milage will vary with each solution, and there is a learning curve in any case. I've been a PHP developer for a long time, and it took me days to figure out how to get connected to SQL Server for the first time from Linux. Thankfully, there are quite a few walkthroughs out there now, and FreeTDS has come a long way since that time.
Hope that helps. :)
I actually have this running on my setup. My best advice is to get on the Homebrew bus.
https://github.com/josegonzalez/homebrew-php is where you're going to want to look for installing PHP and related items. I don't remember exactly what I did but it wasn't particularly difficult.
First you'll need FreeTDS.
brew install freetds
Then, add Jose's formulas to your homebrew (instructions on the github page). After that,
brew install php5x --with-mssql
brew options php5x
if you need more extensions.
Based on Jon Watson's comment,
I've tried step 2, and it doesn't work. check my issue here https://github.com/laravel/laravel/issues/2180
Step 3 is broken link and I think it's the same with step 2.
I also tried linux ODBC driver for Laravel (there are 2, google it), both doesn't work too. Although my simple test php works in both DBLIB and ODBC (compiled using official microsoft odbc unix driver).
Step 4 definitely works, BUT you must use IIS for best stability.
That leaves step 1. OR,
Ditch Laravel4 and use good ol' AdoDB http://adodb.sourceforge.net/ which I've been using since 2006 and still working superbly (although not modern like Laravel) configure it using tutorial in http://docs.moodle.org/20/en/Installing_MSSQL_for_PHP
I wonder why they don't build sqlsrv driver for linux too....
Im trying to run a shell with cakephp but I'm not able to do it due to a SQL connection error, I'm always getting this
Warning:mssql_connect(): Unable to connect to server: XXXXX I'm sure the config for the data source is correct as I'm able to connect using the website side of the app.
Have anyone stumble with something like this?
BTW the webserver and the mssql server are not the same, they are on different hosts.
Environment Info ( I agree is a mess... ):
Web server
Windows server 2003 R2
PHP-5.2.4
IBM http server 6.1
Cakephp 1.2
DB Server
Windows server 2003 R2
Microsoft SQL server 2005
I have isolated the problem and found is not cakephp related, I created a script with just this line of code
mssql_connect('XXXX', 'YYYY', 'ZZZZ', true);
Giving me the same error. This should be something different between CLI and how php is run from the HTTP server.
Thank you!
Make sure you specify the port to connect to (usually 1433). If that still doesn't work its possible you need to play with named pipes settings. More information can be found in the comments on the PHP site: http://ca3.php.net/function.mssql-connect
I would also suggest you look into using the Microsoft SQL Serv drivers for PHP, they are much better maintained than the mssql ones. http://www.microsoft.com/download/en/details.aspx?id=20098 Here is an article explaining the differences: http://blogs.msdn.com/b/brian_swan/archive/2010/03/08/mssql-vs-sqlsrv-what-s-the-difference-part-1.aspx If you do go the sqlsrv route (and I really suggest you do) here are the connection parameters: http://php.net/manual/en/function.sqlsrv-connect.php Use example 3.
Here are the steps I followed to narrow and then fix the problem:
Check which php.ini is your cli using by running the next command: php -i
Isolate the problem, I was thinking it was something with cakephp, but at the end every problem is related to a single line in php, my problem was around this line of code mssql_connect('XXXX', 'YYYY', 'ZZZZ', true);
Based on the info provided here I found out that the next dll was outdated or not compatible with Windows Server 2003, just get ntwdblib.dll ver. 2000.80.2039.0, use this exact version as others like ver.2000.80.194.0 didn't worked for me.
As #charles mentioned if you are not working already in a project already deployed use sqlsrv drivers as those are maintained currently and the mssql are basically getting deprecated.
Thanks!
As a part of the technology standardization in the organization I work at, we're moving from MySQL and Linux to MS SQL Server and Windows. One of the PHP-based applications that we use is Mantis, a bug tracking system available at http://www.mantisbt.org
Has anyone had any luck getting Mantis to work completely with MS SQL Server? I've got Mantis 1.1.8 working for the most part but file attachments do not work, while Mantis 1.2.1 does not install on MS SQL Server.
Here is a step by step guide, maybe this helps out: http://gonfva.blogspot.com/2010/03/mantis-on-sql-server.html
The mantis page states:
It is written in the PHP scripting language and works with MySQL, MS SQL, and PostgreSQL databases and a webserver.
So it is possible, and you might want to use the official mantis support channels.
I can confirm also that Mantis 1.2.x does not install on MS SQL Server. We tried at work but had to move to a LAMP stack to get 1.2.x running. Seems to work with 1.1.x versions.
Also see this forum thread: http://www.mantisbt.org/forums/viewtopic.php?f=3&t=18827
As part of the MantisBT development team I can tell you that although there is code support for MS SQL Server, there are many issues with it. The cause of the problem is that none of the developers - or contributing users - are running an SQL Server installation and we're not aware of any free setups which we can use to the SQL Server.
Long story short: it probably doesn't work out of the box, but you might force it into running by patching it. If you do, please contribute those changes back, as there are many users which reported problems with SQL Server.
I confirm that Mantis 1.2.6 IS successfully installable and usable on IIS 7.5 + PHP 5.3.6
Tips: http://thegrayzone.co.uk/blog/2011/03/setting-up-mantisbt-on-iis-7-w-sql-server/