Problem with the type of Ncode I get from a Sybase comic

Asked

Viewed 55 times

1

Good, I’m getting values from a Sybase database through odbc in php.

It turns out that when printing special characters ,such as ô or ç, are printed '?? ' instead of these.

I have tried using iconv(), utf8 Decode()/Encode(),I have included the code"" and I have tried using the Forceutf-8 class to convert the values but nothing works.

To try to find out the type of Discovery of the data I received I used the mb_detect_encoding() function but it returns me empty in all results with special characters.

Does anyone have a solution or any idea what’s going on? (I cannot directly change the type of database encounter)

Code:

<?php
require 'vendor/autoload.php';


$servidorodbc=file('odbc.txt',FILE_IGNORE_NEW_LINES);
$dsn=$servidorodbc['0'];
$user=$servidorodbc['1'];
$pwd=$servidorodbc['2'];


if($pwd="''"){
  $pwd="";
};
$db = odbc_connect($dsn, $user, $pwd);




$query = odbc_exec($db, 'Select * from GP_Vw_Valores_Pagos where Ano=2019 and Codigo=18990 order by CD');


use \ForceUTF8\Encoding;

echo Encoding::fixUTF8("Fédération Camerounaise de Football\n");
?>


<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <div class="row mt-5 mb-5">
                                        <div class="col-12 col-sm-12 col-m-12 col-l-12 col-xl-12">
                                            <table id="tabela" class="table" ;>

                                                <tr>

                                                    <th scope="col">Descrição</th> 

                                                </tr>

                                                <?php while ( $row = odbc_fetch_array($query)) {
                                                    ?>
                                                    <tr style="text-align: right;">

                                                        <td class="center" style="text-align;"><?=  $row['Descricao']?></td>


                                                    </tr>

                                                <?php }?>
                                            </table>
                                        </div>
                                    </div>
                                    <div class="row mt-5 mb-5">
                                        <div class="col-2 col-sm-2 col-m-2 col-l-2 col-xl-2">
                                            <form method="post">
                                                <input type="submit" name="grafico" class="btn btn-success" value = "Grafico">
                                            </form>
                                        </div>
                                        <div class="col-2 col-sm-2 col-m-2 col-l-2 col-xl-2"></div>
                                        <div class="col-2 col-sm-2 col-m-2 col-l-2 col-xl-2"></div>
                                        <div class="col-2 col-sm-2 col-m-4 col-l-2 col-xl-2"></div>
                                        <div class="col-2 col-sm-2 col-m-2 col-l-2 col-xl-2">
                                            <form action="../../app/excel.php" method="post">
                                                <input type="submit" name="export_excel" class="btn excel" value = "Exportar para excel">
                                            </form>
                                        </div>
                                        <div class="col-2 col-sm-2 col-m-2 col-l-2 col-xl-2"><a class="btn buttonstyle mr-5" target="_blank" href="../../app/imprimePA.php">Imprimir</a></div>
                                    </div>

</body>
</html>

1 answer

0

Right now $db = odbc_connect($dsn, $user, $pwd); which is the solution, you need to set the connection to be made in UTF-8 so:

<?php
    $dsn.="CharacterSet => UTF-8";
    $db = odbc_connect($dsn, $user, $pwd);
?>

But for this, make sure that the contents of the variable $dsn has been ; at the end, to avoid other errors.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.