php access mssql 2005 database, sqlsrv drivers - php

I am attempting to access a mssql 2005 database using Microsoft's supplied sqlsrv drivers. I have tried every driver version from 3.1 to 2.0, installing a different version of XAMPP with different versions of PHP installed.
version 3.1 = php version 5.4.7
error:
This extension requires the Microsoft SQL Server 2012 Native Client.
Access the following URL to download the Microsoft SQL Server 2012
Native Client ODBC driver for x86
version 3.0 = php version 5.3.1 error:
This extension requires either the Microsoft SQL Server 2008 Native
Client (SP1 or later) or the Microsoft SQL Server 2008 R2 Native
Client ODBC Driver to communicate with SQL Server. Neither of those
ODBC Drivers are currently installed. Access the following URL to
download the Microsoft SQL Server 2008 R2 Native Client ODBC driver
for x86:
version 2.0 = php version 5.2.1 and 5.2.4
Php drivers are unrecognized and do not appear in phpinfo().
I am under the impression the extension should support ALL EDITIONS of SQL Server 2005 and greater...
I installed both the SQL Server 2012 Native Client and the SQL Server 2008 Native Client (SP3).
According to this article I can test the ODBC connectivity to a SQL Server.
Entering odbcping at a command prompt returns:
'odbcping' is not recognized as an internal or external command....
I checked the ODBC Data Source Administrator and found the ODBC Driver 11 for SQL Server is listed in the drivers tab.
Any assistance as to what I may be missing?

You are mixing up two things: ODBC and PHP drivers for MS SQL Server 2005.
If you install SQLDRV 3.X, you dont use ODBC.
If you use ODBC, then you may need different PHP driver than SQLDRV.
I also struggled few hours with setting up PHP connection to MS SQL Server 2003, 2005, 2008 with Studio Express. I used pdo_sqldrv driver installed via SQLDRV drivers provided by Microsoft. Installing PHP drivers was easy part. Once you see pdo_sqldrv in phpinfo(), you are done with PHP driver. Difficult is second part - setting up properly MSSQL environment to allow PHP for connection. I did following steps:
downloaded & installed free MSSQL Studio Express 2005 (or 2008, both work fine)
installed or upgraded to dotNetFx40Setup.exe
installed msxml6.msi (I think this was only needed for version 2005)
installed MSSQL Native Client
logged into studio and created new user for PHP only with read/write permissions
enabled pipe and other connection resources
figured out correct connection string "sqlsrv:server=PCHOME\\SQLEXPRESS;database=eshop"
Then it worked, but definitely it was not easy setup. G'd luck.

Related

Should one use FreeTDS driver instead of MS SQL Driver for compatibility between older PHP and newer SQL Servers?

I was struggling to connect my Drupal (7.43) application (hosted on a PHP 5.4 server) to a Microsoft Azure SQL database.
I got really depressed and even found myself arguing with my company's DBA for why did you install this database on the newest version of SQL Server?.
Edited:
The reason why I asked that was because of Microsoft official documentation which says one should not connect to newer versions of SQL Servers if PHP server version is under 7.*.
System Requirements for the Microsoft Drivers for PHP for SQL Server
https://learn.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-ver15#driver-versions
According to this article, if PHP server version is 5.4, the official MS driver for such php server is 3.2 version. Therefore, if the SQL Server driver is 3.2, it should not connect to SQL Server version higher than 2014.
TL; DR;
I used FreeTDS to connect 5.4 PHP application to Azure SQL Server! Yaay
FreeTDS is re-implementation of C libraries originally marketed by Sybase and Microsoft SQL Server. It allows many open source applications such as Perl and PHP (or your own C or C++ program) to connect to Sybase or Microsoft SQL Server.
My operational system is CentOS 7.
I installed basic yum packages for http server and php database connection.
yum install httpd httpd-tools php php-common php-cli php-odbc php-pdo unixODBC unixODBC-devel
So far I understand:
PDO stands for PHP Data Objects.
ODBC stands for Open Database Connectivity -- which is a standard application programming interface for accessing database management systems.
Alright, I then installed FreeTDS:
yum install epel-release
yum check-update
yum install freetds freetds-devel
Then I had /etc/freetds.conf:
[MYCLIENT]
host = myclient.database.edtech.com
port = 6669
tds version = 8.0 # Btw, how important is this version for old PHP servers versus new SQL servers?
I also had /etc/odbcinst.ini
[FreeTDS]
Driver = /lib64/libtdsodbc.so.0
FileUsage = 1
Furthermore, I had /etc/odbc.ini:
[MSSQLServer]
Driver = FreeTDS # Yes, ODBC will use FreeTDS, I get it.
Description = MSSQL Server
Trace = Yes
Server = myclient.database.edtech.com
Port = 6669
TDS_Version = 7.1 # Shouldn't this be same as the version in /etc/freetds.conf?
Database = ApplicationDB
Conclusions
I hope this question helps others.
FreeTDS is a different driver
than Microsoft's.
PHP does not know about FreeTDS not FreeTDS knows
about PHP version.
As far as I understood from the answers, there is
a ODBC bridge/layer in between them.
Better use the newest FreeTDS
version to make sure the connection works.
You said
The reason why I asked that was because of Microsoft official documentation which says I cannot connect to newer versions of SQL Server if my PHP version is below 7.*.
and
Is this php 5.4 connection really supposed to work with newest SQL
Server despite the official Microsoft docs say it should not?
...but actually, the Microsoft documentation you're talking about doesn't say you can't connect to SQL Server from PHP 5.4.
They said you can't (or at least you are not supported to) do that by using the Microsoft Drivers for PHP for SQL Server - which is the specific product that documentation is talking about.
FreeTDS is a different driver. By replacing the driver, you've replaced the thing which Microsoft is saying you shouldn't use. AFAIK Microsoft have no involvement with FreeTDS, so what they support, and what their driver works with, is entirely up to them.

PHP 7 on IIS: Call_user_function could not be located

I am trying to use the Microsoft SQL Server drivers with PHP 7.1 Not Thread Safe x64 on Windows 2012 R2 64-bit server.
No matter what I do I am getting an error when I run php from a admin command prompt
Warning: PHP Startup: Unable to load dynamic library
'ext\php_pdo_sqlsrv_7_nts.dll' - The specified procedure could not be
found.
Additionally it display a windows pop up that states
The procedure entry point call_user_function could not be located in
the dynamic link library C:\PHP7\ext\php_pdo_dqlsrv7_nts_x64.dll
I have verified that the php.ini is pointing to a file that exists, because if I rename the .dll file, the error messages changes to "specified module could not be found", instead of specified procedure.
I have installed Microsoft Visual C++ runtime 15 x64 as required by PHP 7.
I have installed Microsoft ODBC driver 13 as required by the Microsoft SQL Server driver.
I have rebooted the server twice.
There is nothing else I can think to even try. The Microsoft WinCache.dll is loading and working fine in PHP, as verified by phpinfo.
Confirmed what #MEmerson said above. You need to downgrade PHP to 7.0.X(?) - I used 7.0.12.
Complete Setup:
Windows 10 Pro
PHP X64 7.0.12 TS (Bitnami WAMP Stack)
Microsoft ODBC Driver 13.1 for SQL Server (https://msdn.microsoft.com/en-us/library/mt703139(v=sql.1).aspx)
Microsoft Drivers for PHP for SQL Server 4.0 (https://www.microsoft.com/en-ca/download/details.aspx?id=20098)
Same drivers with PHP X64 7.1.0 produced the error you are getting.
Microsoft Drivers 4.3 for PHP for SQL Server are now available.
These drivers contains files for PHP 7.1 - php_pdo_sqlsrv_71_nts_x64.dll etc.
I've successfully managed to connect to SQL server.
Had similar error when tried to use httpd (Apache), PHP 7.2.2, Microsoft ODBC driver 11 on MS Windows Server 2012. The text of error was:
The procedure entry point call_user_function could not be located in the dynamic link library php_pdo_sqlsrv_7_ts_x64.dll.
when I called php -m to check modules.
So I have downloaded Windows-7.2.zip from https://github.com/Microsoft/msphpsql/releases and used thread-safe dlls from it.
php -m works now as it should without giving error.
Same as NoCopy
Windows Server 2012
php-7.0.15-Win32-VC14-x64.zip from (http://windows.php.net/download)
Visual C++ Redistributable for Visual Studio 2015 (https://www.microsoft.com/en-us/download/details.aspx?id=48145)
Microsoft ODBC Driver 13.1 for SQL Server
Microsoft Drivers for PHP for SQL Server 4.0
7.1.x still a No,NO from Microsoft
It happened to me today while enabling the extensions in the IIS, where I by mistake enabled different versions for pdo & driver extensions (E.g. php_sqlsrv_7_nts_x86.dll for PHP 7.0 & php_pdo_sqlsrv_72_nts_x86.dll for PHP 7.2).
Usually the package that you download from Microsoft that contains Microsoft Drivers 5.3 for PHP for SQL Server has all the PHP extensions versions. https://www.microsoft.com/en-us/download/details.aspx?id=57163
Just make sure you enable both extensions for the same versions to avoid that error.

installing PHP 5.4 or higher with sqlsrv on Win 2003 server

I have to upgrade an application that is installed on a win 2003 server from PHP 5.2 to PHP 5.4 or higher. The datacenter tell us to keep OS untouched if possible.
The sqlsrv driver is acusing the following error, that is a common issue when installing sqlsrv dll:
Erro -49
This extension requires the ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712
Erro 0
The question is that ODBC Driver 11 for SQL Server apparently is only available on win 2008 server or higher, as described on the link above.
Is there any solution to upgrade PHP on this server and replace mssql extension to sqlsrv under the current OS (win 2003)?
Unfortunately, it seems like an answer is no. According to official system requirements docs, on Windows 2003 is currently supported only sqlsrv version 2.0 and it's only for PHP 5.2/5.3. I think this kind of version support is nothing new in Microsoft world.

Connecting to MSSQL via php on Server 2012

I've been wanting to upgrade my windows web servers to 2012 but have hit a bottleneck. I currently use the microsoft sqlsrv driver to connect however Microsoft server 2012 does not support 32 bit ODBC connectors which that driver uses. I was going to upgrade to the 64 bit version of PHP however microsoft has not created a driver for that version.
What methods are supported on windows server 2012 to connect PHP 5.4+ to Microsoft SQL 2008+?
Microsoft php sqlsrv driver for php 5.4 needs SQL Server Native Client for SQL server. And it works well with SQL server 2012 x64 and even 2014 x64.
Official php 5.4 divers can be downloaded from here
http://www.microsoft.com/en-us/download/details.aspx?id=20098
Read this thread about drivers for php 5.5
http://sqlsrvphp.codeplex.com/discussions/441706
There is a download link there to unofficial php 5.5 drivers. Someone with nick wshmstr published drivers recompiled for php 5.5.
I use them in production for a year now with SQL server 2012 and 2014 without any problems.
All these drivers are for Windows 2008, 2012 server x86/64 and for x86 php only.

PHP 5.5.0 w/ Microsoft SQL Server 2008 R2 - No sqlsrv_connect()?

I have the following environment:
Windows Server 2008 R2
IIS 7.5
Microsoft SQL Server 2008 R2
I want to use the new PHP 5.5.0 version, which works just fine per sé, but I can't connect to the MSSQL server due to the lack of current drivers.
For my previous PHP 5.4.15 version, I used the official Microsoft drivers from >here<.
Is there yet any possibility to connect from PHP 5.5.0?
PHP 5.5 compiled with VC11, so the driver must be compiled with VC11 too. You can download PHP SQL Server driver (compiled with VC11) from here:
SQL Server PHP Driver For PHP 5.5
Official driver from Microsoft has now been released (12/12/2014) .. you can download it here
Version 3.1 now supports PHP 5.5 and requires Microsoft ODBC Driver 11
(or higher) for SQL Server

Categories