dousongxuan7507 2014-12-09 15:58
浏览 133
已采纳

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

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条回答 默认 最新

  • duan111112 2014-12-10 16:35
    关注

    I have uninstalled WampServer64 and installed WampServer32. Then everything is OK now.

    My connection object

    $conn = new PDO('sqlsrv:Server='.$host.';Database=' . $db, $user, $pass, 
                    array(
                          PDO::ATTR_EMULATE_PREPARES => false,
                          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
                         )
                   );
    

    There is another point: I have incidently typed .mdf extension after database name which should not be. Because if I write it I get

    28000 - SQLSTATE[28000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'zkanoca_dbuser'.

    error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,