Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

php - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 '...extphp_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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...