如何在我的 windows 2008 Server 2008 R2 上安装 pdo_sqlsrv? [关闭]

Posted

技术标签:

【中文标题】如何在我的 windows 2008 Server 2008 R2 上安装 pdo_sqlsrv? [关闭]【英文标题】:How can I install pdo_sqlsrv on my windows 2008 Server 2008 R2? [closed] 【发布时间】:2013-04-19 21:08:47 【问题描述】:

我正在尝试使用 PDO 连接到 SQL Server 数据库。我一直在努力解决这个问题,现在我在尝试连接到 SQL Server 的页面上遇到了这个致命错误

致命错误:带有消息“SQLSTATE[IMSSP]”的未捕获异常“PDOException”:此扩展需要 Microsoft SQL Server 2012 Native Client ODBC 驱动程序才能与 SQL Server 通信。访问以下 URL 以下载适用于 x86 的 Microsoft SQL Server 2012 Native Client ODBC 驱动程序:http://go.microsoft.com/fwlink/?LinkId=163712'

我已经从 http://www.microsoft.com/en-us/download/details.aspx?id=20098 (SQLSRV30.EXE) 我已将这些驱动程序放在 Server 2008 R2 服务器上安装 php 的 ext 目录中。

我还在 php.ini 文件的扩展名列表末尾添加了这两行

extension=php_pdo_sqlsrv_53_nts.dll
extension=php_sqlsrv_53_nts.dll

我正在使用 PH PVersion 5.3.19 服务器 API CGI/FastCGI 线程安全已禁用

我确实看到了pdo_sqlsrv,但我没有看到客户端 API 版本。

我还需要做什么才能使用 PDO 连接到具有 SQL 数据库的远程服务器?我需要在远程服务器上安装任何东西吗?

这是我的 php 我的管理部分的截图

这是我的连接类

<?php

class connection 

    private $connString;
    private $userName;
    private $passCode;
    private $server;
    private $pdo;
    private $errorMessage;
    protected $lastQueryTime;
    protected $lastQuery;

    private $pdo_opt = array (
                            PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
                            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                            PDO::mysql_ATTR_INIT_COMMAND => "SET NAMES utf8"
                            );




    function __construct($dbName = DATABASE_NAME, $serverName = DATABASE_HOST)

        //sets credentials
        $this->setConnectionCredentials($dbName, $serverName);

        //start the connect
        $this->startConnection();

    

    function startConnection()


            $this->pdo = new PDO($this->connString, $this->userName, $this->passCode, $this->pdo_opt);

            if( ! $this->pdo)

                $this->errorMessage  = 'Failed to connect to database. Please try to refresh this page in 1 minute. ';
                $this->errorMessage .= 'However, if you continue to see this message please contact your system administrator.';
                echo $this->getError();
            
    


    //this will close the PDO connection
    public function endConnection()

        $this->pdo = null;
    

    //return a dataset with the results
    public function getDataSet($query, $data = NULL)
    
        $start = microtime(true);
        $cmd = $this->pdo->prepare( $query );

        $cmd->execute($data);
        $ret = $cmd->fetchAll();
        //$cmd->closeCursor();
        $this->lastQueryTime = microtime(true) - $start;
        $this->lastQuery = $query;

        return $ret;
    



    public function processQuery($query, $data = NULL)
    
        $start = microtime(true);
               //$this->pdo->beginTransaction();


        $cmd = $this->pdo->prepare( $query );
        $ret = $cmd->execute($data);
               //$this->pdo->commit();
               //$cmd->closeCursor();
        $this->lastQueryTime = microtime(true) - $start;
        $this->lastQuery = $query;

        return $ret;
    


    //return last insert id
    public function lastInsertId($name = NULL) 
        if(!$this->pdo) 
            return false;
        

        return $this->pdo->lastInsertId($name);
    



    public function getOneResult($query, $data = NULL)
        $cmd = $this->pdo->prepare( $query );
        $cmd->execute($data);

        return $cmd->fetchColumn();
    

    public function getError()
        if($this->errorMessage != '')
            return $this->errorMessage;
        else
            return true;  //no errors found

    

    //this where you need to set new server credentials with a new case statment
    function setConnectionCredentials($dbName, $serv)

        switch($serv)


            //MS SQL server
            case 'SQLSERVER':
                $this->connString   = 'sqlsrv:server='.$serv.';database='.$dbName;
                $this->userName     = 'username';  
                $this->passCode     = 'password';  
            break;

            //the defaults are predefined in the APP_configuration file - DO NOT CHANGE THE DEFAULT
            default:
                $this->connString   = 'mysql:host='.DATABASE_HOST.';dbname='.DATABASE_NAME.';charset=utf8';
                $this->userName     = DATABASE_USERNAME;
                $this->passCode     = DATABASE_PASSWORD;
            break;

            

    


public function lastQueryTime() 
    if(!$this->lastQueryTime) 
        throw new Exception('no query has been executed yet');
    
    return $this->lastQueryTime;


public function lastQuery() 
    if(!$this->lastQuery) 
        throw new Exception('no query has been executed yet');
    
    return $this->lastQuery;








?>

这就是我使用我的类来提取数据集的方式

<?php
include('connection.php');

$sql_db = new connection('databaseName','SQLSERVER');

$call_details = $sql_db->getDataSet('SELECT
                                    LocalUserId AS loginName,
                                    RemoteNumberCallId AS PhoneNumber,
                                    SUM(CallDurationSeconds + HoldDurationSeconds + LineDurationSeconds) AS totalTalk
                                    FROM dbo.CallDetail WHERE LocalUserId = \'blah\' AND RemoteNumberCallId = \'123456789\'
                                    GROUP BY LocalUserId, RemoteNumberCallId');


$call_details->endConnection();

?>

我什至尝试过这段代码,所以我不会使用我的课程,但我仍然遇到同样的错误

 $ss = new PDO("sqlsrv:server=SQLSERVER; Database=databaseName", "userName", "Password");

【问题讨论】:

没什么。应该很好去..尝试使用sqlsrv_query 您的评论。什么是 sqlsrv_query?以及如何使用它? sqlsrv_querysqlsrv_ 系列 PHP 函数的一部分,它可以替代 PDO。这不会帮助你,因为你的问题在 PHP 之外,在驱动程序/操作系统级别。 【参考方案1】:

我已经换了

扩展=php_sqlsrv_53_nts.dll
extension=php_pdo_sqlsrv_53_nts.dll

扩展=php_pdo_sqlsrv_53_nts_vc9.dll
extension=php_sqlsrv_53_nts_vc9.dll

Insted on using SQLSRV30.EXE 我用的是 SQLSRV20.EXE 这行得通。

@FreshPrinceOfSo 感谢您的帮助 :)

谢谢:)

【讨论】:

在 Win 2008 R2 x64、SQL Server 标准版(64 位)、IIS 6 和 PHP 5.3 上解决了这个问题,并启用了 php_pdo_sqlsrv_53_ts_vc9.dll 和 php_sqlsrv_53_ts_vc9.dll。【参考方案2】:

我个人安装的 Windows Server 2008 R2 和 PHP/SQL Server 配置。

    从PHP Downloads 下载 VC9 x86 Non Thread Safe 的最新稳定 .zip 版本 解压到您的 PHP 目录中 下载Microsoft Drivers 3.0 for PHP for SQL Server 解压到你的PHP目录\ext

    将以下扩展写入php.ini

    [PHP_SQLSRV_54_NTS]

    extension=php_sqlsrv_54_nts.dll

    [PHP_PDO_SQLSRV_54_NTS]

    extension=php_pdo_sqlsrv_54_nts.dll

【讨论】:

我就是这么做的。但是由于我已经安装了 php5.3.19,所以我进入了您的第 3 步,并将其添加到我的 php.ini 文件 [PHP_SQLSRV_54_NTS] extension=php_sqlsrv_54_nts.dll [PHP_PDO_SQLSRV_54_NTS] extension=php_pdo_sqlsrv_54_nts.dll 中。这是行不通的。我不确定是什么问题。我需要在此服务器上安装 SQL 吗?请注意,MS SQL 未安装在此服务器上(我在其中运行我的 php 脚本)但它安装在我尝试连接到 SQL 服务的远程保留区 我可以将评论作为重复的 VTC 吗? 以防万一你第一次没有得到它,@FreshPrinceOfSO @Mike 你确定你的 PHP 安装是 NTS 吗?您确实需要在盒子上安装 SQL Server。我们可以看看你的 PHP 代码吗? 我可以将评论作为重复的 VTC 吗?

以上是关于如何在我的 windows 2008 Server 2008 R2 上安装 pdo_sqlsrv? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章