【已解决】请教一下PDO连接MSSQL

浏览:7114 发布日期:2015/02/20 分类:求助交流
扩展已经开了,如下Thread Safety    enabledPDO drivers    mysql, oci, odbc, sqlite, sqlsrvpdo_sqlsrv

pdo_sqlsrv support    enabled

Directive    Local Value    Master Value
pdo_sqlsrv.client_buffer_max_kb_size    10240    10240
pdo_sqlsrv.log_severity    0    0
以上是PHPINFO中的信息

在WAMP中已经开启扩展,以下是连接代码<?php


try {
    $hostname = "127.0.0.1";
    $dbname = "ABIS_FOOD";
    $username = "sa";
    $pwd = "123456";
    $dsn = "sqlsrv:Server=$hostname;database=$dbname";
    
    $conn = new \PDO($dsn, $username, $pwd);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "mssql database connnection sucessed!";
} catch (PDOException $e) {
    echo "Failed to get DB handle: " . $e->getMessage() . "\n";
    exit();
}
运行时提示出错信息Failed to get DB handle: SQLSTATE[IMSSP]: This extension requires the ODBC Driver 11 for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712请过来人指点一下。多谢

祝大家新年愉快,万事如意



已经解决了,在WIN下原来还需要装一个msodbcsql.msi
最佳答案
评论( 相关
后面还有条评论,点击查看>>