phparraysjsonstringodbc

array_push in array from odbc connection not working


i have this data.php file that must fill an array with a query result from an ODBC conection to an MDB Msaccess file.

<?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);

?>

The problem is that I cant get the Json if I use the first Field that is a Name in a string type field. But if I use the last field it works like a charm.

I Try:

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

but doesnt work either


Solution

  • I did it adding "utf8_encode" in the variables inside the while.