Configure PHP to work with MSSQL by using SQLSRV - php

I'm trying to configure PHP to work with MSSQL database. I found some instructions on the internet, but I didn't succeed.
I'm using php 5.3, MS SQL 2008, server is Openserver 5.2.2, OS is Windows 8.1.
I installed MS SQL Management studio 2008.
I installed ODBC driver
I installed SQLSRV version 53_ts_vc9 (from phpinfo() (vession - 5.3,
thread safe, compiler - MSVC9))
I've added extension=php_sqlsrv_53_ts_vc9.dll line to php.ini
I've rebooted server and got "--without-mssql" "--without-pdo-mssql"
in phpInfo()
Help me, guys. What have I done wrong?

I've rebooted server and got "--without-mssql" "--without-pdo-mssql"
in phpInfo()
Those are compile time options, not configuration options. You need to compile php from source, or get a module that provides that functionality.

Related

Sqlsrv dll does not properly load on IIS

I am using PHP 7.3 and trying to run sqlsrv but I cannot get my PHP environment to load sqlsrv. I look at the phpinfo and the extension does not show up. These are the steps I have taken.
Through the Web Platform Installer, I have installed PHP 7.3 for IIS, the SQL Server Driver, and the Windows Cache Extension.
I have put php_sqlsrv_73_nts_x64.dll in the extension directory.
I have verified my php.ini configurations.
Downloaded and installed the latest Microsoft ODBC driver.
Found the bug. Turns out I was had installed the SQL Server Driver for IIS when I really needed the SQL Server Driver for IIS Express.

Configuration Issues with SQLSRV for PHP for MSSQL

I am installing a configuration with WampServer 2.4:
- Windows 7 64-bit sp1
- WampServer 2.4 64-bit
- PHP 5.4.3 64-bit (came with the WampServer)
- Apache 2.4.4
- Microsoft SQL Server 2012 Native Client 64-bit
- Microsoft SQLSRV 3.0 (php_sqlsrv_54_ts.dll, php_pdo_sqlsrv_54_ts.dll and they are put in c:/wamp/bin/php/php5.4.3/ext/
And I edited the C:\wamp\bin\apache\Apache2.4.4\bin\php.ini with the lines:
- extension_dir = "c:/wamp/bin/php/php5.4.3/ext/"
- extension=php_sqlsrv_54_ts.dll
- extension=php_pdo_sqlsrv_54_ts.dll
And I restarted all the services from Wamp.
But I still couldn't see the SQLSRV section from phpinfo -- and of course my connection test program failed.
What might have gone wrong?
Can anyone help?
Your issue is because you are using (or WAMP has given you) 64bit php, where as your sqlsrv driver is most likely 32bit.
Your solution is to switch to a 32bit version of php (The benefits of running in 64, are pretty much non existent anyway unless you need larger data types), or to recompile the sqlsrv driver in 64bit (Likely more trouble than it is worth).
Try a WAMP 32 bit version. http://www.wampserver.com/en/#wampserver-32-bits-php-5-4
Also if Apache and my-sql are of no consequence to you (they are just a web sever and and an sql database) you can install a WISP PHP Stack in a breeze using the web platform installer. http://www.microsoft.com/web/downloads/platform.aspx
For those of you using a 64bit version of PHP, the unofficial dll files linked below will work:
http://robsphp.blogspot.co.uk/2012/06/unofficial-microsoft-sql-server-driver.html
I am using 64bit WAMP on a 64bit Windows Server and was about to call it quits before I found those DLL files. It's odd that the official DLLs don't work with 64bit PHP, but I'm glad I at least found a solution.
I'm using just Apache 2.2 and PHP 5.4 in 32bit with SQLSRV 3.0 and it is now working. Note that the Thread Safe is set to Yes, thus SQLSRV ts.dlls should be used. It was a struggle. Hope this helps others.

'Error!: could not find driver' after installing php_[pdo_]mssql.dll on WampServer

Similar questions seem to be all over the internet, but so far nothing has helped.
I'm currently running WampServer with Apache 2.4.4 and PHP 5.4.12 on Windows Server 2008 R2. According to the PHP documentation the drivers necessary to connect to an MSSQL server ship with the distribution; they do not. Neither php_mssql.dll (which the documentation claims is no longer necessary for PHP5.4, but which is still referenced in php.ini. Who knows) nor php_pdo_mssql.dll are present in the distribution.
Several sources pointed to these drivers from Microsoft, however I had no success either renaming the respective drivers to php_mssql.dll/php_pdo_mssql.dll or keeping the names the same (php_sqlsrv_54_nts.dll, php_pdo_sqlsrv_54_ts.dll, etc.) and modifying php.ini to point to the proper driver. Though I didn't get an error upon starting apache as I do when the driver is simply missing, I received Error!: could not find driver when attempting to point to a test php page at localhost.
This article seemed the most promising, but unfortunately ntwdblib.dll is not included in the zip distributions of PHP, contrary to what the article claims. This seems like it should be a laughably simple problem: missing drivers, which are supposedly readily available. And yet here I am... What am I doing wrong?
In case anyone else ends up here while trying to solve this problem, here are the steps that have worked for me the two times I've done it. These steps worked both on Windows Server 2008 R2 and Windows 8.
For my purposes, I used the latest 32-bit (x86) version of WampServer (at the time of this writing, it was 2.4, and came with Apache 2.4.4 and PHP 5.4.16). The 32-bit version is necessary, as the drivers are 32-bit; the 64-bit version will not work.
Install Microsoft Visual C++ 2010 Redistributable Package x86
Install Microsoft SQL Server 2008 Native Client x86 (Click "Download" and select ENU\x86\sqlncli.msi. Once again, the 64-bit version will not work)
Install Microsoft ODBC Driver 11 x86 (Click "Download" and select 1033\x86\msodbcsql.msi)
Install Microsoft SQLSRV driver 3.0 in php/ext/ (For my installation, this was C:/wamp/bin/php/php5.4.16/ext/)
Edit Apache's php.ini to include the line extension=php_pdo_sqlsrv_54_ts.dll (for my installation, this was located in C:/wamp/bin/apache/Apache2.4.4/bin/)
You have to place the file in the directory for PHP/ext (bin/php/ext depending on your Wamp / Xampp installation). However, you also need the SQL server native client as per: http://msdn.microsoft.com/en-us/library/cc296170.aspx

PHP (WAMP) OCI8 driver setup problem

Greetings,
I need to install oci8 drivers for PHP, but I’m having some trouble.
I already have a WAMP install, which comes with the oci8 extension, and have done the following in effort to set it up:
Enabled the extension by adding the following to my php.ini file in my Apache docroot as a local variable:
[PHP_OCI8]
extension=php_oci8.dll
Added my extensions directory path to my PATH environment variable on windows (c:/wamp/bin/php/php5.3.0/ext/;)
Added the same extensions directory to my php.ini file
When I start up my wamp I see the following error message:
PHP Startup: Unable to load dynamic library ‘c:/wamp/bin/php/php5.3.0/ext/php_oci8.dll’
I’m able to verify that the above path is correct, and am tempted to say that there’s something wrong with the .dll, but I’m not sure.
Has anyone experienced similar issues?
The Oracle OCI8 driver also requires that the Oracle Instant Client 10gR2 (aka 10.2.x) libraries or newer be installed on the machine PHP is running on. It is recommended you use either the Basic or Basic Lite version depending on if you need the internationalization libraries or not.
Win32 Instant Client Download Page
Win64 Instant Client Download Page
An annotation: I recently had the task of installing PHP 5 on a Windows system with Oracle HTTP Server 10g. PHP <= 5.0 requires an Oracle 8i or 9i client, PHP >= 5.1 requires an Oracle 10gR2 client or above. The Oracle HTTP Server 10g deploys an Oracle 10gR1 client which is not at all supported by PHP 5 (at least on Windows, maybe one can compile by himself...),
but contains PHP 4.3.9 as an Apache module. I couldn't use it: some PHP modules that are required need at least PHP 5.0.
Solution was: return to Oracle HTTP Server from the 9i companion CD while running a 10gR2 database in a separate Oracle Home.

PHP - SQL Server 2005 express to 2008 standard problem

I have a PHP app running happily on the following system:
web app: PHP version 5.2.3
OS: Windows Server 2003 Standard 32 bit
database: SQL Server 2005 (express)
web server: IIS 6
I'm trying to get the same thing running on the following:
web app: PHP version 5.2.11
OS: Windows Server 2008 Standard 64 bit
database: SQL Server 2008 Standard 64-bit
web server: IIS 7
After doing the install and setup I usually do, phpinfo() is running but there is no MSSQL section. I've looked around and found some MS documentation to set up the system using a php_sqlsrv.dll and tried that but it seems to use a different interface to connect to the database (no more mssql_connect(), now it's sqlsrv_connect()). Is this the only way to connect php to SQL Server 2008 or do I just have the setup wrong? If I can go back to PHP 5.2.3 and have it work, that will be fine but I didn't want to undo what I have if it won't help.
Thanks,
There is an extensive tutorial on MSDN on how to do this.
http://msdn.microsoft.com/en-us/library/cc793139%28SQL.90%29.aspx
The extension named php_mssql.dll is linked with an old Microsoft library (ntwdblib.dll). This library was last updated with MS SQL Server 6.5. It's a 32 bit library and does not support many of the new features introduced in newer versions of the database. It is possible to compile a version of the extension using FreeTDS. That will give access to the latest version of the TDS protocol. This also allows you to access SQL Server from a Linux/Unix based system.
The extension named php_sqlsrv.dll is developed and maintained by Microsoft gives much better support for the newer versions of SQL server and it should work in both the environments you describe.
There should be a dll named php_mssql.dll in the ext folder of your php installation. You will want to make sure this is being loaded in your php.ini file with extension = php_mssql.dll . If that is not showing in phpinfo() after restarting the webserver it may be that you have installed the wrong thread safe version of PHP depending on how you've set things up with Fast CGI. You shouldn't have a problem using sqlsrv (SQL Server Driver for PHP). I would however recommend using version 1.1 of the driver as it has some improvements and supports SQL Azure. One thing you will notice is that datetime columns come back as PHP DateTime objects instead of strings. I've also noticed that you run into a lot less problems if you just install the stack with the Microsoft Web Platform Installer.
After having this issue and almost tearing my hair out for hours and giving up, I found the answer:
http://docs.moodle.org/22/en/Installing_MSSQL_for_PHP#Using_FreeTDS_on_Windows
php_dblib.dll is the "new" dll that supports the old mssql php functions (mssql_connect() etc). So basically this new dll replaces php_mssql.dll and everything just works as it did before. (Well it does for me now)
My server setup is:
O/S: Windows Server 2008,
DB: MSSQL Server 2008 R2,
PHP: 5.3.13
Excerpt from phpinfo():
System Windows NT XXXXXXXXXXXXX 6.1 build 7601 (Windows Server 2008 R2
Enterprise Edition Service Pack 1) i586 Build Date May 8 2012 18:41:52
Compiler MSVC9 (Visual C++ 2008) Architecture x86
Configure Command cscript /nologo configure.js
"--enable-snapshot-build" "--enable-debug-pack" "--disable-zts"
"--disable-isapi" "--disable-nsapi" "--without-mssql"
"--without-pdo-mssql" "--without-pi3web"
"--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared"
"--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared"
"--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared"
"--with-enchant=shared" "--enable-object-out-dir=../obj/"
"--enable-com-dotnet" "--with-mcrypt=static"
"--disable-static-analyze"
Server API CGI/FastCGI
Virtual Directory Support disabled
Configuration File (php.ini) Path C:\Windows
Loaded Configuration File C:\Program Files (x86)\PHP\v5.3\php.ini
Hope this saves someone some time.

Categories