I got a PHP project which uses Medoo for accessing a database on MS SQL Server 2012. I used to test my project on the same server, but since copy-pasting through remote desktop got kinda annoying and inefficient, I wanted to move on a local system, so I installed Xampp (with PHP 5.6.19 VC11). Since I still need to use the server database, I first encountered the problem that the PDO MSSQL extension is not available anymore, and my script failed to send a query to the database. So tried using the SQLSRV 3.0 extension instead (5.4 thread-safe - why isn't there a version 5.6? Is 5.4 supposed to be forward compatible?), which still sends me an uncaught exception with message 'could not find driver', thrown from the PDO constructor and forwarded through Medoo. I'm not sure if this fails on Medoo, the driver, or something else. Moving the database to phpMyAdmin is no option... Has anyone an idea how I can solve this?
All information you need are on this this web page https://msdn.microsoft.com/en-us/library/cc296170(v=sql.105).aspx.
As you can see you need version 3.2 for PHP 5.6 support. I found download link and information about adding SQLSRV extension to php.ini for you.
https://www.microsoft.com/en-us/download/details.aspx?id=20098
https://msdn.microsoft.com/en-us/library/cc296203(v=sql.105).aspx
Finally you have to install Microsoft ODBC Driver 11 for SQL Server.
In short, download SQLSRV 3.2, add PDO extension to php.ini (choose right version for your PHP), install Microsoft ODBC Driver 11 for SQL Server on your local enviroment.
Related
I have a PHP application that is already hosted on Windows IIS Server.But when i try to run it now then it shows me the error."db driver not found".BUT i have installed Microsoft Drivers 5.6 for PHP for SQL Server .But still getting error.I'm using SQL Server Express 14.0.1000.169 version.
Is this a correct driver version to download ? or what is the error?.
firstly, are you sure you chose the correct dll for your computer to be the php extension? version, thread safety, system architecture. All of these matter. If that is correct then you can move on to the next step which are drivers.
When I start XAMPP it gives me the following error when trying to load the SQL Server driver for PHP.
The procedure entry point _zend_hash_index_update##24 could not be located in the dynamic link library D:\xampp\php\ext\php_sqlsrv_72_ts_x64.dll.
I have tried downloading both the Microsoft SQL Server Driver 4.0 and 5.6 for php and use the php_sqlsrv_7_ts_x64.dll and php_sqlsrv_72_ts_x64.dll in the extension directory and add them to php.ini.
I found this posting related to this error:
PHP 7 on IIS: Call_user_function could not be located
In the system requirements, for MSSQL driver 4.0 it states that this driver is good for PHP 7.0+. In trying 5.6, I found this posting saying that it's support for PHP 7.3:
https://blogs.msdn.microsoft.com/sqlphp/2019/03/01/drivers-5-6-for-php-for-sql-server-released/
Either way, I still receive the same error. Is there something else I need to be checking?
In short go to https://learn.microsoft.com/en-us/sql/connect/php/microsoft-php-drivers-for-sql-server-support-matrix?view=sql-server-2017#php-version-support.
Then compare your php version against driver version in a table displayed.
Finally download a correct version, that is all.
use the 7.3 one instead (php_sqlsrv_73_...)
I was receiving this error also, trying to load php_sqlsrv_7_nts_x86 for php-7.3.8-nts-Win32-VC15-x86.
If you look at this support matrix on the microsoft site you'll see plenty of other options for drivers that support your PHP version.
I downloaded the latest, the SQLSRV561 package. That did the trick.
So Just to be clear,
I loaded php_sqlsrv_73_nts_x86.dll (from SQLSRV5.6.EXE) instead of php_sqlsrv_7_nts_x86 (from SQLSRV4.0.EXE), and that fixed the problem.
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 am trying to access an SQL Server.
UPDATE: In response to Clive's comments below I have also tried reinstalling the native ODBC driver but no change.
I've checked over all the questions I can find on this and everything seems to be in order. My server details:
PHP 5.4 (Managed via Plesk)
SQL Server 2008 R2 SP2
Windows Server 2008 R2
The latest mssql drivers for PDO are in the EXT directory and referenced in php.ini:
extension=php_sqlsrv_54_nts.dll
extension=php_pdo_sqlsrv_54_nts.dll
PHPINFO() gives the following:
PDO Drivers: mysql, sqlite, sqlsrv
pdo_sqlsrv support: enabled
sqlsrv support: enabled
My connection string looks like this:
$DSN = "sqlsrv:Server=myDbServer,1433;database=my-dbname";
$PdoOptions = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$sparklyGenericPdoObj = new PDO($DSN,'myUsername','myPasswurde', $PdoOptions);
But that just gives me the following error which links - in a roundabout way - to the drivers I already have installed (I've checked the version numbers):
PHP Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[IMSSP]: This extension requires the Microsoft SQL Server
2012 Native Client ODBC Driver to communicate with SQL Server. Access
the following URL to download the Microsoft SQL Server 2012 Native
Client ODBC driver for x86:
http://go.microsoft.com/fwlink/?LinkId=163712'
On this thread (reporting exactly the same error as me) is a solution which says that you can confirm the driver is installed by looking for the items I've mentioned above in PHPINFO: Not getting connected to Sql Server 2012!
Any help would be much appreciated!
Although it is a fairly old post, I've decided that it would be better to place my answer here instead of creating an other question...
after 3 weeks of research all over the Web and testing a lot of hypothesis around php installation, php code and drivers installation, I finally found the solution to this question.
THE PROBLEM:
I have an app that is installed on WIN SERVER 2012 SP2 and running under IIS.
The development of this app is made on a WIN 7 SP1 and running under 32-bit XAMPP 3.2.2. All of these are running PHP 5.6.
Everything is working fine on the server but I keep having this message when executed locally on XAMPP:
This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server
Even though I've installed this driver many times (with other php drivers found here, configure my php.ini to load php_sqlsrv_56_ts.dll and php_pdo_sqlsrv_56_ts.dll), it keeps returning me the same message...
The PDO command I've used to connect to distant MSSQL Server was:
$db = new PDO("sqlsrv:server=192.168.165.XXX;Database=testDB;", "userName", "passWord");
I have tried other drivers and it worked fairly well with ODBC driver;
$db = new PDO("odbc:Driver={SQL Server};Server=192.168.165.XXX;Database=testDB;", "userName", "passWord");
but I've found that there was some limitations with the later driver that I didn't experience with sqlsrv on the PROD server so I decided to push a little bit more my research to find a way to implement sqlsrv on my local machine...
THE INVESTIGATION:
Before connecting with PHP, I've tried to create System DSN (Data Source Name), with the ODBC Source Administrator (ODBCSA) application and test connection from there before trying to connect with my application.
Something pretty strange I have discovered with Win7, is that there are two different ODBCSA applications.
The 32-bit version of the Odbcad32.exe file is located in the %systemdrive%\Windows\SysWoW64 folder.
The 64-bit version of the Odbcad32.exe file is located in the %systemdrive%\Windows\System32 folder.
The 32-bit version of the ODBC Administrator tool displays 32-bit system DSNs, 32-bit user DSNs, and 64-bit user DSNs.
The 64-bit version of the ODBC Administrator tool displays 64-bit system DSNs, 32-bit user DSNs, and 64-bit user DSNs
Just to make sure what ODBCA your are using, check in Task manager under odbcad32.exe, if you see *32 on its right, that means its the 32-bit version.
At first, I executed the 64-bit ODBCSA, created DSN using the brand newly installed ODBC Driver 11, called ODBC_11_64 and test the connection using the ODBCSA. All worked fine. When I tested my code I received an other error message:
The specified DSN contains an architecture mismatch between the Driver and Application
Ok then, I tried to create an new DSN using the 32-bit ODBCSA. It was strange at first, when I've discovered that there was no version number aside some driver names and I received this error from the ODBCSA:
The setup routines for the ODBC Driver 11 for SQL Server could not be found. Please reinstall the driver.
and an other message:
Component not found in the registry
It was obvious that there was an installation problem and the later message point me in the right direction, the Registry...
Starting regedit as admin, I've found that all 64-bit ODBC drivers can be found here:
HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI
All 32-bit ODBC drivers can be found here:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI
While trying to access the 64-bit key (\ODBC Driver 11 for SQL Server), I was able to display key values but when I tried to access the 32-bit key, I received this message:
Error Opening Key, ODBC Driver 11 for SQL Server Driver cannot be opened.
An error is preventing this key from being opened.
Details: Access is denied.
THE SOLUTION:
By right clicking on the 32-bit faulty key I was able to access permission interface. I was then able to add my username (I could also add a group) and granted full Control on the registry key.
I then came back to creating an new DSN using the 32-bit ODBCSA and ODBC Driver 11 for SQL Server, tested the connection with SUCCESS! :-)
I when back to my application and found that I was able to access the distant MSSQL SERVER using sqlsrv, on my local machine.
All along it was the driver installation package that was faulty! I should had install permissions to SYSTEM, users and administrators to the key has it did with the 64-bit registry key for this driver.
It was a pretty long story but I thought it was worth it, since a lot of persons tried to solve this complex problem, going in many different directions without success. Its also my contribution to all of you, who failed to find the solution but helped me in my investigation ;-)
i have fond some config in php.ini but was noted;
;extension=odbc
;extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
remove “;” before, restart service, and it is worked!
In the end I solved this by installing the "Microsoft® SQL Server® 2012 SP1 Command Line Utilities" from here (SqlCmdLnUtils.msi):
http://www.microsoft.com/en-in/download/details.aspx?id=35580
No idea why this worked but there it is.
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....