dousongxuan7507
dousongxuan7507
2014-12-09 15:58

如何配置wampserver使用PDO连接到mssql服务器?

  • php
  • pdo

I am trying to connect to a MSSQL DB server using PDO. I have downloaded some .dll files from Microsoft's web page and copied them to wampserver's wamp\bin\php\php5.5.12\ext folder. Then I edited php.ini which is located at wamp\bin\apache\apache2.4.9\bin folder.

I added the following lines:

extension=php_pdo_sqlsrv_55_ts.dll
extension=php_sqlsrv_55_ts.dll
;extension=php_sqlsrv_55_nts.dll
;extension=php_pdo_sqlsrv_55_nts.dll

I have shutdown wampserver and run it again. I can see those four extensions on the menu PHP -> PHP Extensions, when I click on wampserver's tray icon.

Then I have tried to create a connection using the code below:

$conn = new PDO('sqlsrv:Server=1.2.3.4,1433;Database=database.mdf', 
                'user', 'password', 
                array(PDO::ATTR_EMULATE_PREPARES => false,
                      PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
               );

When I call the page from browser I get

could not find driver

error.

First, How can I connect to mssql server with PDO? Second, Is there any point I missed about insatallation and/or configuration?

EDIT

Below, you can see my php.ini file's extensions section.

extension=php_bz2.dll
extension=php_curl.dll
extension=php_com_dotnet.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_gmp.dll
extension=php_intl.dll
extension=php_imap.dll
;extension=php_interbase.dll
extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_exif.dll      ; Must be after mbstring as it depends on it
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll      ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll  ; Use with Oracle 11gR2 Instant Client
extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
extension=php_shmop.dll
; The MIBS data available in the PHP distribution must be installed. 
; See http://www.php.net/manual/en/snmp.installation.php 
;extension=php_snmp.dll
extension=php_soap.dll
extension=php_sockets.dll
extension=php_sqlite3.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
extension=php_xmlrpc.dll
extension=php_xsl.dll  
extension=php_pdo_sqlsrv_55_ts.dll
extension=php_sqlsrv_55_ts.dll
;extension=php_sqlsrv_55_nts.dll
;extension=php_pdo_sqlsrv_55_nts.dll

EDIT 2:

Finally I have discovered that my dll files ara incompatible with my current wampserver64. I am looking for the correct files.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答