dongpa3109 2013-06-25 06:00
浏览 62
已采纳

Windows更新PDO SQL Server驱动程序问题

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.

error is

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

The above query returns an error

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 )

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;
}

Actual function that's causing an error

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

1条回答 默认 最新

  • doushi6932 2013-06-25 08:15
    关注

    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); 
    

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题