Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过PDO从MS SQL Server 2005中选择数据,其中_Php_Sql Server_Pdo_Character Encoding - Fatal编程技术网

Php 通过PDO从MS SQL Server 2005中选择数据,其中

Php 通过PDO从MS SQL Server 2005中选择数据,其中,php,sql-server,pdo,character-encoding,Php,Sql Server,Pdo,Character Encoding,我有这个问题。我应该使用PDO从数据库(MSSQLServer2005)中选择数据。我有一个带有函数的用户类 public function select($sql, $array = array(), $fetchMode = PDO::FETCH_ASSOC) { //try... if not catch exception try{ $sth = $this->DBH_->pr

我有这个问题。我应该使用PDO从数据库(MSSQLServer2005)中选择数据。我有一个带有函数的用户类

public function select($sql, $array = array(), $fetchMode = PDO::FETCH_ASSOC) 
        { 
            //try... if not catch exception 
            try{ 
              $sth = $this->DBH_->prepare($sql); 

              foreach ($array as $key => $value) { 
                $sth->bindValue("$key", $value);                    
              } 

              // run the query 
              $sth->execute(); 
              return $sth->fetchAll($fetchMode); 
            } 
            catch(PDOException $e) { 
                echo "<p class="error_msg">Ошибка. Свяжитесь с программистами.</p>"; 
                file_put_contents('errors.log', date("Y-m-d H:i:s")." - ".$e->getMessage().". File:".$e->getFile().". Line: ".$e->getLine()."\n", FILE_APPEND); 
                exit(); 
            } 

        }
我怎样才能修好它

对不起,如果我有语法错误。我的英语不是很好


谢谢…

您必须将FreeTDS协议版本设置为高于4.2的版本,因为nvarchar列直到sql server 2005(或其附近)才引入,它们无法编码到协议中。编辑/etc/freetds/freetds.conf

[global]
;tds version = 4.2
tds version = 7.2

当您在management studio中运行相同的查询时,是否得到结果?@Szymon,是的,我得到结果
[global]
;tds version = 4.2
tds version = 7.2