Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.2K
Views
PDO sqlsrv: could not find driver

I trying to connect to an SQL Server in PHP. With XAMPP on my local machine, everything works well. But now I going to bring my application on the production server.

On this server there is installed the Microsoft IIS 6.1 and running the PHP version 7.0.7. I also installed the ODBC Driver from here. Next I decomment the following line in my php.ini file:

extension=php_sqlsrv_7_nts.dll
extension=php_pdo_sqlsrv_7_nts.dll

I got the files from the official microsoft site.

What's my problem?

Unfortunately, after I restarted the IIS. The PDO function throws the PDOException error with the following message:

could not find driver

For the connection I am using the following function which works pretty well on my local machine:

try {
    $con = new PDO("sqlsrv:Server=" . SERVER . ";Database=" . DATABASE, USERNAME, PASSWORD);
    // set the PDO error mode to exception
    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo "No connection: " . $e->getMessage();
    exit;
}

What can I else do?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Here is detailed process if it's helpful for someone. PHP Version - 7.4

  1. Download and extract the .dll files from this link - https://docs.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15

  2. Paste the files in C:\xampp\php\ext, your path could be different.

  3. in php.ini add those two lines at bottom or in extension section.

     extension=php_sqlsrv_74_ts_x64.dll
     extension=php_pdo_sqlsrv_74_ts_x64.dll
    
  4. Restart your Xampp server, I'll suggest restart your computer and everything will work without an issue then.

Check if SqlSRV enabled

Check using phpinfo() or http://localhost/dashboard/phpinfo.php at like this -

SQLSrv Driver Check in PHP Info

Hope, it will help someone.

about 4 years ago · Santiago Trujillo Report

0

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.

about 4 years ago · Santiago Trujillo Report

0

It took some time for me to solve the 'No driver'-error. I went through some steps as mentioned here and found some other ones that helped me after new errors. For future references:

  • Download the latest drivers from Microsoft (as said by Julian Schmuckli).
  • Check if your XAMPP is 64 bits(!) with Phpinfo(). If you've got 32-bit, you need different drivers.
  • Add the drivers to your Php.ini file and save the dll's in your php/ext-folder (question of saber tabatabaee yazdi).
  • For the connection, use this code:
$dbh = new PDO ("sqlsrv:Server=$server;Database=$dbname",$username,$pw); 

If you add a port, use:

$server = "192.168.1.15, 51022";

Where the IP (can be hostname to) is your server and 51022 your port.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!