Windows更新PDO SQL Server驱动程序问题 [英] windows update PDO SQL Server driver issue

查看:94
本文介绍了Windows更新PDO SQL Server驱动程序问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows apache环境中使用PHP通过pdo连接sql服务器. 我的代码运行良好,没有任何错误.使pdo插入查询无法正常工作的Windows机器上的最新更新.为了确认此错误不是由于最近的更改,我已从SVN恢复为旧版本.仍然存在相同的错误.

I am using PHP in windows apache environment for connecting sql server using pdo. My code was running perfectly with out any errors. recent update on windows machine making pdo insert query not working. To confirm this error is not because of recent changes, I have reverted to older versions from SVN. Still same error exists.

错误是

INSERT INTO contactus(contactref, title, first_name, last_name, email) VALUES('35008679022', 'Mr', 'Robin', 'Michael', 'robin@robin.com')

上面的查询返回错误

Array ( [0] => HY000 [1] => 10007 [2] => Incorrect syntax near '35008679022[10007] (severity 5) [INSERT INTO contactus(contactref, title, first_name, last_name, email) VALUES('Mr] [3] => -1 [4] => 5 )

但是,当我复制查询并在SQL Server Management Studio中运行它时,它运行没有任何错误.

But, when i copy the query and run it in SQL server management studio, It runs without any error.

任何人都可以帮助我找出这个问题吗?

Can anyone please help me to find out this issue?

function newInsertQuery( $tbl, $flds, $prepVals, $valsArr ) {
    try {
        $dbcon = $this->mysqlConnect();
        $q = "INSERT INTO $tbl($flds) VALUES($prepVals)";
        $prep = $dbcon->prepare($q);
        if( $prep->execute($valsArr) ) {
            $rq = 1;
            $q = "SELECT SCOPE_IDENTITY() as ins_id";
            $rq = $dbcon->query($q);
            $optArr = $rq->fetchAll(PDO::FETCH_ASSOC);
            $_SESSION['last_id'] = $optArr[0]['ins_id'];
        }
        else {
            $rq = 0;
        }

        $_SESSION['q_error'] = $dbcon->errorInfo();
    }
    catch( Exception $ex ) {
        $rq = 0;
        echo $ex->getMessage();
    }

    //clear connection
    $dbcon = null;
    return $rq;
}

导致错误的实际功能

$flds = 'contactref, title, first_name, last_name, email'; 
$prepVals = '?, ?, ?, ?, ?'; 
$valsArr = array('35008679022', 'Mr', 'Robin', 'Michael', 'robin@robin.com');
newInsertQuery('contactus', $flds, $prepVals, $valsArr);

推荐答案

最后,我发现了问题,这是由于计算机和Windows服务器上的Windows最近更新所致.此更新后,mssql pdo驱动程序将引发此错误.我已经从Microsoft网站下载了sqlsrv20驱动程序并放置了文件
php扩展目录中的php_pdo_sqlsrv_53_ts_vc6.dll并在php.ini文件中添加了新扩展名,例如extension = php_pdo_sqlsrv_53_ts_vc6.dll并更改了pdo连接性

Finally, I have found the issue, This is because of recent windows update on my machine and our windows server. After this update mssql pdo driver throws this error. I have downloaded sqlsrv20 driver from microsoft website and placed the file
php_pdo_sqlsrv_53_ts_vc6.dll inside php extension directory and added new extension in php.ini file like extension=php_pdo_sqlsrv_53_ts_vc6.dll and changed the pdo connectivity

$dbcon = new PDO( "sqlsrv:server=$conf->host;Database=$conf->db_name", $conf->db_user, $conf->db_pwd); 

注意:对于Wamp服务器,用户还需要检查apache中的php.ini,并且需要在apache下的php.ini文件中添加扩展名.

Note : for wamp server users needs to check php.ini in apache also and needs to add the extension in php.ini file under apache.

这篇关于Windows更新PDO SQL Server驱动程序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆