PDO MSSQL Server - Driver not found
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
PDO sqlsrv: could not find driver
After I found the error log on the Windows Server, I solved the error by myself.
I got this error in my log:
[21-Apr-2017 07:12:14 UTC] PHP Warning: PHP Startup: Unable to load dynamic library '...\ext\php_pdo_sqlsrv_7_nts.dll' - %1 is not a valid Win32 application. in Unknown on line 0
Then I downloaded again the driver and installed the x64-Driver. Finally It works without any problems.
PHP Sql Server PDOException:could not find driver
I got it figured out. I had to install the ODBC Driver 17 for SQL Server (msodbcsql_17.2.0.1_x64.msi) on my server. The SQL Server Native Client 11.0 was installed but not the ODBC Driver for SQL Server.
For future reference for anyone else with this or a similar issue...
It can be downloaded at https://www.microsoft.com/en-us/download/details.aspx?id=56567 (note: if you have a 32 bit server, you will want to install the msodbcsql_17.2.0.1_x86.msi - If you accidentally try to install the incorrect version, it will let you know during the installation). After the driver is installed, you need to reboot the server. It won't prompt you to restart, but you'll need to.
In my PHP.ini I have added extension=php_pdo_sqlsrv_72_nts.dll
and extension=php_sqlsrv_72_nts_x64.dll
They can be downloaded at https://learn.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-2017
More info can be found at https://learn.microsoft.com/en-us/sql/connect/php/loading-the-php-sql-driver?view=sql-server-2017 and https://learn.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-2017
I can now establish a connection to Sql Server using either sqlsrv_connect or PDO.
PDO connection test:
$SqlServer = "THISSERVER\SQLEXPRESS";
$SqlServerCon = new PDO("sqlsrv:server=$SqlServer;Database=TheDatabase", "DbUName", "DbPassword");
if (!$SqlServerCon) {die('Unable To Connect to Sql Server');}
else
{echo "Connection Successful";}
sqlsrv_connect connection test:
$SqlServer = "THISSERVER\SQLEXPRESS";
$DbConnInfo = array( "Database"=>"TheDatabase", "UID"=>"DbUName", "PWD"=>"DbPassword");
$SqlServerCon = sqlsrv_connect( $SqlServer, $DbConnInfo);
if( $SqlServerCon ) {echo "Connection established";}
else
{echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));}
MSSQL PDO could not find driver
mssql
is the old way of doing it, sqlsrv
should be more appropriate! In fact the extension is called (extension=php_pdo_sqlsrv_53_ts_vc9.dll) as well ;)
try {
$DBH = new PDO("sqlsrv:Server=xxxx;Database=xxxx", 'xxxx', 'xxxx');
} catch (PDOException $e) {
echo $e->getMessage();
}
Hope this helps!
Source : http://php.net/manual/fr/ref.pdo-sqlsrv.connection.php
PHP / PDO / SQL Server. Uncaught PDOException: could not find driver
Had already downloaded the driver and it didn't work. Found a new site for the driver and this one works.
https://github.com/Microsoft/msphpsql/releases
php.ini line added:
extension=php_pdo_sqlsrv_7_nts.dll
PDOException::(could not find driver) Laravel & sql server
Ah, WAMPServer has 2 seperate php.ini
files.
One is used by PHP under Apache and the other by the PHP CLI.
I see you are using the CLI, so you need to check that you have included the SQL Server drivers extension in the CLI php.ini
file.
You will find that in:
C:\wamp64\bin\php\php{version}\php.ini
You have to edit this manually, there is no menu link to do this, the menu link to edit the php.ini
only edits the PHP under Apache version of php.ini
Make sure you edit the
php.ini
file in the folder that matches the version of PHP you are actually using for this project, as of course you can have multiple versions of PHP installed under WAMPServer
UPDATE: Second Problem
You have added the 32bit AND 64 bit SQL Server drivers to your ext folder!
Your WAMPServer menu shows
1. php_sqlsrv_72_ts_x64
2. php_sqlsrv_72_ts_x32
3. php_pdo_sqlsrv_72_ts_x64
4. php__pdo_sqlsrv_72_ts_x32
as you are using 64 bit wamp, you should only have these 2
1. php_sqlsrv_72_ts_x64
2. php_pdo_sqlsrv_72_ts_x64
Related Topics
Extracting Matches from PHP Regex
Sharing PHP Session ($_Session) Across Multiple Domain
Nginx + PHP-Fpm 7.1 - 504 Gateway Time-Out
Html5 Input Type File's Multiple Attribute Not Working in Ie
How to Avoid Using PHP Global Objects
How to Remove a Password from a PDF File Using PHP
PHP - Override Existing Function
PHP Static Method Call with Variable Class Name and Namespaces
How to Get a List of MySQL Databases in PHP Using Pdo
Php: How to Check If the Client Is Local
Twig Problem with PHP 7.4 in Write Variable
How to Use MySQLi Bind_Param Dynamically
Pass Base64 Jpeg Image to Og:Image
Set the Option Available for Select Based on Another Select PHP