PDO MSSQL Server - Driver not found - php

I am currently trying to connect to my localdb on MSSQL 2012 Express.
I have downloaded and installed the official microsoft driver from http://www.microsoft.com/en-us/download/details.aspx?id=20098
I get some kind of SQLSRV section in my phpinfo(). But when I try to create a new PDO object it says it does not have the driver. Which I could understand since it is not mentioned on the phpinfo() PDO section, but it has its own section + the get_loaded_extensions also shows sqlsrv. I suppose thats from the official MS Driver ? I am using the php_sqlsrv_53_nts.dll
With my Zend Server CE 5.6 with PHP 5.3.9
Now as far as I understood I downloaded the wrong driver and should try the one that is brought by the PECL manager? There is only the sourcecode available and obviously I am on a windows machine so I can forget about everything that I need to compile myself - I am actually getting the suffix errors when using the powershell and my pecl / pear installation.
Has anybody solve that problem ? Any help much appreciated
All the best,
Richard

The PDO Extension is not the same as the native driver Microsoft is offering. For PDO you must enable
extension=php_pdo_mssql.dll
in your php.ini.
Normally this file (php_pdo_mssql.dll) should be in your PHP extension-directory (C:...\php\ext). If it's not there you can download PHP from http://windows.php.net/download/ and just take the extension from a package there (take one that correspond with your PHP version of course).
//edit: just read you latest comment. This extension is available for a very long time now and can be considered working. If you are not allowed to use it you must rewrite your code to use the functions the native driver offers for PHP.

Another possibility is to use the odbc drivers which are by default included in the php extensions, you still might have to uncomment them in your php.ini though.
extension=php_pdo_odbc.dll
Don't forget to restart your server afterwards ;-)
And then use it like this:
$db = new PDO('odbc:Driver={SQL Server};Server=192.168.x.x;Database=DatabaseName; Uid=User;Pwd=Password');
$stmt = $db->query("SELECT the_usual FROM aTable WHERE all='well'");

Alright. I suppose its just one of these days.
I got the wrong extension loaded from the supplied ones by MS. I needed to use php_pdo_sqlsrv_53_nts
rather than
php_sqlsrv_53_nts
Thanks for all the help

Related

Working with MS SQL SERVER on PHP5.6

So I have a trouble here. Tried use mssql_connect() but interpeter says that function is undefinied. PHP.net advices this, but it suppports only older versions of PHP. Is it possible to connect to MS SQL Server database from PHP5.6? What extensions should I add, what functions can I use?
Configuration details: localhost, Apache 2.4, PHP 5.6, OS Windows 8.
You need to enable the MSSQL extension in the PHP.ini file.
If this extension is not installed, you need to install it in PHP.
Please tell your server details (OS/WebServer like apache nginx) so that I can explain in detail.
Use
<?php phpinfo();?>
to see what are available with your php installation. I advice you to use PDO instead of mysql_* functions. It supports several databases not only MSSQL or MySQL.

how to get mssql_connect to work on windows 7

I have mssql_* functions working on my Ubuntu installation and want to duplicate this on my windows 7 box. I have installed wamp on the win7 box, but I cannot get it to see the mssql_* functions. I have read many posts about nothing is working. I have the ext directory properly set. I have extension=php_mssql.dll do not see the mssql section in phpinfo, but I do see sqlsrv section. I would like my prod and test environment to match.
Thanks in advance for any assistance
Dean-O
I just checked my local wampserver 2.1 installation, and although there's an option to enable the php_mssql extension, it's missing from the extensions directory.
You can try the FreeTDS extension, which supposedly works fine under both *nix and Windows.
The Moodle wiki specifies that the Microsoft SQL Server driver has "known problems":
WARNING: This driver has known problems and is therefore not suitable
for any Moodle production servers.
and recommends the use of FreeTDS instead (by installing the php_dblib extension). Moodle is a known user of MSSQL, and a respected project, but they don't really specify what they mean by "known problems", so you can take this with a grain of salt...
http://docs.moodle.org/24/en/Installing_MSSQL_for_PHP
If FreeTDS doesn't work for you, you can try installing the official Microsoft drivers:
http://www.microsoft.com/en-us/download/details.aspx?id=20098

Cannot find php_sqlsrv extension - 5.3, threadsafe

I've followed the answer to this question to the letter:
Connection between MSSQL and PHP 5.3.5 on IIS is not working
I'm using XAMPP with threadsafe 5.3. I've copied the files to the extension directory (while leaving them in the /php folder) and I've added the extension lines:
extension=php_sqlsrv_53_ts.dll
extension=php_pdo_sqlsrv_53_ts.dll
When I do this, Apache fails to start, giving me errors in eventvwr like:
Application popup: Warning : PHP Startup: Unable to load dynamic library
'C:\xampp\php\ext\php_sqlsrv_53_ts.dll'
- The specified module could not be found.
Except, obviously, that that file DOES exist in that spot, and php.ini is pointed at that extension directory.
What's the problem?
Windows reports this when a shared lib dependency of what you're loading is missing. Use depends.exe to view the dependencies of php_sqlsrv_53_ts.dll and make sure it's either previously loaded or in the shared library search path.
http://www.dependencywalker.com/
See below url
php_sqlsrv.dll: gives error when checking PHP version but extension works
Read it:-
Since PHP 5.3, Microsoft has a new driver for windows :
http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx
Maybe you can try this version, which seems quite recent (06/2011)
Hope that helps !
Sadly, none of the answers addressed the issue or were avenues I had already explored.
I have decided to use the ODBC drivers with a SQL Server connection string, which seems to work fine, minus the fact I can't use MSSQL and SQLSRV native functions.
I have written a page that might help when installing the SQLSRV driver:
http://robsphp.blogspot.co.uk/2012/09/how-to-install-microsofts-sql-server.html
Unfortunately the instructions got complicated when MSFT removed the download for the old XP/2003 driver (version 2.0), so read the whole page before starting.
Wrong technology, but I was having problems getting WAMP to connect to MSSQL, with the same types of errors.
I fixed the problem by installing the 32-bit version of WAMP (instead of 64, even though we were on a 64-bit system).
Even if that's not applicable to the OP, I hope someone finds this helpful!
I was getting the same error messages when I started the Drupal 7 stack after installation. I am using VM Ware with Win 7 x64 and acquia-drupal-win-7.31.36-6159.54300.
I went to the PHP site http://php.net/manual/en/sqlsrv.requirements.php and installed the x64 Package.
steps
1) Stop Drupal Stack
2) run the file: sqlncli.msi
3) restart Drupal, and no error messages.

mssql_connect in PHP does not exist

I've been struggling with this for a while now and I don't know what I'm missing. The error is:
call to undefined function mssql_connect()
Having looked into it already, I've done about everything I can.
I moved the php.ini file to c:\windows
In the ini I changed the extension_dir directive to c:PHP\ext and uncommented:
extension = php_mssql.dll
I moved the dll file to c:windows\system32\
I downloaded the 200.80.194.0 version of ntwdblib.dll and placed it in c:\windows\system32
I restarted my web server client
PHP is still not recognizing the function and library classes. I'm stumped as to what I didn't do right and would love some help. If it's helpful, I'm running PHP 5.3.2, IIS, and Microsoft SQL Server 2008.
For SQL Server 2008 on Windows it's sqlsrv_connect This is because Microsoft now uses the SQL Driver for PHP which is now on version 2.0 I believe.
Also it's worth noting that with sqlsrv_query, and mssql_query they switched the parameters around (spent half an hour figuring that out).
You say you are running PHP 5.3.2. The PHP manual states:
This extension is not available anymore on Windows with PHP 5.3 or later.
The PHP MSSQL library is ancient and is no longer considered a viable option.
You should instead examine PDO with either the MSSQL driver or the more reliable ODBC driver.
Microsoft are still developing their own PDO driver. Version 2 was made available June 2010. Microsoft recommend the more stable version 1.1 for production use.

Is there a place I can find all the extensions of PHP?

Now I'm seeking of php_pdo_mysql.dll version 5.2.5.5,
only found this:
http://dllcentral.com/php_pdo_mysql.dll/5.2.5.5/
But my zend studio 5.5 says it's invalid!
Is there any other place I can try my luck?
Brrr, I really wouldn't download binaries (that could do anything they please on the system, and possibly even the web pages that get served) from locations like that.
Isn't PDO included in PHP by default since 5.0?
From the PDO installation manual:
PDO and all the major drivers ship with PHP as shared extensions, and simply need to be activated by editing the php.ini file:
THe pdo extentions come default with php installation as far as I know.
You should try to uncoment the package in your php.ini file and then reload apache.
Looking at this I would have thought that you wouldn't need a DLL at all. From here:
PDO ships with PHP 5.1, and is
available as a PECL extension for PHP
5.0; PDO requires the new OO features in the core of PHP 5, and so will not
run with earlier versions of PHP.
Official binaries can be found at:
http://windows.php.net/download/
However, you say you already have a Windows binary. Look at it carefully: you should already have that DLL available. Probably, you need to rerun the installer and select that extension.

Categories