douxian3828 2018-12-18 08:39
浏览 182

连接ODBC与特殊字符

I have a database connection that I have made with a odbc connector. The problem is that I have a field that has special characters, such as accents, and it does not recognize them.

This is my webservice:

<?php
    define('CHARSET','UTF-8');
    header('Content-Type: text/html; charset=UTF-8');

    $usuario='';

    $pass='';

    $dsn='Tr3';

    $conexion = odbc_connect($dsn,$usuario,$pass);


   $sql="select total, name, domin from F_VENTA where Ve_FirmaCamion=true";


    $rs = odbc_exec($conexion, $sql);
    if (!$rs) {
        exit("Error al conectar la base de datos");
    }
    $datos = array();
    $i = 1;

    while($row = odbc_fetch_array($rs)) {

        $datos[] = $row;
        $i++; 
    }


    odbc_close($conexion);

    $json = json_encode($datos);

    echo $json;

?>

This works perfectly. But if the field "name" has some special character (accents, ñ, Ç ...) then the webservice does not return anything to me. The json leaves me blank.

I tried with:

utf8_decode($json);

and

$cadena= htmlentities($json, ENT_QUOTES, "UTF-8");

but don't work.

Any advice? Thanks!

  • 写回答

1条回答 默认 最新

  • dongye8110 2018-12-18 16:47
    关注

    I bring my solution to the problem in case it happens to someone else.

    I have managed to solve if before coding the data to json, I pass the mb_convert_encoding() method to the data that comes to us from the database while it traverses it. So I'll encode them in the while loop:

    while($row = odbc_fetch_array($rs)) {
    
                $datos[] = mb_convert_encoding($row, "UTF-8", "iso-8859-1");
    
                $i++;
    } 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)