【问题标题】:array_push in array from odbc connection not working来自 odbc 连接的数组中的 array_push 不起作用
【发布时间】:2017-05-15 17:19:28
【问题描述】:

我有这个 data.php 文件,它必须用从 ODBC 连接到 MDB Msaccess 文件的查询结果填充数组。

<?php

header('Content-Type: application/json');

$con = odbc_connect('MyDB','','pass');


if (!($con))
{
echo "Failed to connect to DataBase: " ;
}else
 {
 $data_points = array();

        $result =odbc_exec($con, "SELECT  CategoryName , Sum(DetalleFacturasA.P_NETO) AS Total, Periodo
    FROM TheTable
 GROUP BY month(FacturasA.Fecha), year(FacturasA.Fecha), CategoryName;");

while(odbc_fetch_row($result))
{        
    $NameVal= odbc_result($result,1) ;

    $YVal=odbc_result($result,2);

    array_push($data_points,array( "y" => $YVal ,"label" => $NameVal));        
}

echo json_encode($data_points, JSON_NUMERIC_CHECK);

}
odbc_close($con);

?>

问题是如果我在字符串类型字段中使用第一个名称字段,我将无法获取 Json。但如果我使用最后一个字段,它就像一个魅力。

我试试:

 $point = array("label" => odbc_result($result,['CategoryName']) , "y" => 
 odbc_result($result,"Total"));

但也不行

【问题讨论】:

    标签: arrays json string odbc


    【解决方案1】:

    我在while里面的变量中添加了“utf8_encode”。

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 2018-08-11
      • 1970-01-01
      • 2017-07-21
      • 2018-09-16
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      • 2013-01-24
      相关资源
      最近更新 更多