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
804 views
in Technique[技术] by (71.8m points)

php - MSSQL PDO could not find driver

I'm using PHP Version 5.3.8 that was installed via XAMPP along with Microsoft SQL Server 2008 R2 (SQLEXPRESS). I have the drivers installed correctly (i guess) and have added the correct line into php.ini (extension=php_pdo_sqlsrv_53_ts_vc9.dll to be exact).

I'm trying to connect to the server like so:

try {

    $DBH = new PDO("mssql:host=xxxx;dbname=xxxx", 'xxxx', 'xxxx');

} catch(PDOException $e) {

    echo $e->getMessage();
}

I get the "could not find driver" error, and I've tweaked it all kinds of ways to solve the problem. I've tried all other kinds of drivers, but this is the only one that Apache doesn't give me an error on startup. When I run phpinfo(), the pdo_sqlsrv fields are all blank except pdo_sqlsrv.log_severity which is set to 0.

I DL'd my drivers from microsoft, and I've tried both 2.0 and 3.0

Any advice would be awesome!!

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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

examples from documentation


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

...