Problems with SQL Server 2008 encoding

0

I am performing a query on a Sql Server database, however the special characters are returned as follows:

MAR�O

instead of

MARÇO

I was able to fix using the utf8_encode() function, but I do not want to have to deal with each result, and by doing some research, I understand that it is possible to configure the connection so that the information already comes with encoding correct, but not yet I was able to apply. Here's my connection class for better viewing:

<?php

class pdo_dblib_mssql {

    private $db;
    private $cTransID;
    private $hostname;
    private $port;
    private $dbname;
    private $username;
    private $pwd;
    private $table;
    private $columns;
    private $where = array();
    private $childTrans = array();

    public function __construct($data, $table) {
        $this->hostname = $data['host'];
        $this->port = $data['port'];
        $this->dbname = $data['schema'];
        $this->username = $data['user'];
        $this->pwd = $data['password'];

        $this->table = $table;

        $this->connect();
    }

    public function connect() {
        try {
            $this->db = new PDO("dblib:host=$this->hostname:$this->port;dbname=$this->dbname", "$this->username", "$this->pwd");
        } catch (PDOException $e) {
            $this->logsys .= "\n Failed to get DB handle: " . $e->getMessage();
        }
    }

    public function beginTransaction() {

        $cAlphanum = "AaBbCc0Dd1EeF2fG3gH4hI5iJ6jK7kLlM8mN9nOoPpQqRrSsTtUuVvWwXxYyZz";
        $this->cTransID = "T" . substr(str_shuffle($cAlphanum), 0, 7);

        array_unshift($this->childTrans, $this->cTransID);

        $stmt = $this->db->prepare("BEGIN TRAN [$this->cTransID];");
        return $stmt->execute();
    }

    public function rollBack() {

        while (count($this->childTrans) > 0) {
            $cTmp = array_shift($this->childTrans);
            $stmt = $this->db->prepare("ROLLBACK TRAN [$cTmp];");
            $stmt->execute();
        }

        return $stmt;
    }

    public function commit() {

        while (count($this->childTrans) > 0) {
            $cTmp = array_shift($this->childTrans);
            $stmt = $this->db->prepare("COMMIT TRAN [$cTmp];");
            $stmt->execute();
        }

        return $stmt;
    }

    public function close() {
        $this->db = null;
    }

    public function select($columns){
        $this->columns = $columns;

        return $this;
    }

    public function where($column, $value, $op = "=") {
        $this->where[] = "$column $op '$value'";
        return $this;
    }

    public function get(){
        $sql = "SELECT " . implode(", ", $this->columns) . " FROM $this->table WHERE " . implode(" AND ", $this->where);
        $stmt = $this->db->prepare($sql);
        $stmt->execute();
        $ret = $stmt->fetchAll();

        var_dump($ret);die;
    }
}

Note: This database is a third-party database, which gives me a view to query, so higher database configurations are not possible.

The collation of view is Latin1_General_CI_AS

Is it possible to treat these characters automatically in some way, by doing some configuration on the connection or before doing the query?

    
asked by anonymous 14.11.2016 / 20:01

1 answer

0

Tried?

setAttribute( PDO::SQLSRV_ENCODING_UTF8 ); 
    
15.11.2016 / 12:19