How to make the data return in php array

0

I need to return the data in an array. I'm doing this, but the data does not return:

<?php
ini_set('display_errors', true);
error_reporting(E_ALL);

include_once("conexao.php");
$pdo = conectar();

header('Content-Type: application/json');
header("Access-Control-Allow-Origin: *");

/*$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$idCategoria = $request->idCategoria;*/

$id_categoria = $_GET['idCategoria'];
echo $id_categoria;

$buscarSubcategoria=$pdo->prepare("SELECT * FROM sub_cat_entrada WHERE id_categoria = :id_categoria");
$buscarSubcategoria->bindValue(':id_categoria', $id_categoria, PDO::PARAM_INT); 
$buscarSubcategoria->execute();

//$buscarSubcategoria->debugDumpParams();


$return = array();

while ($linha=$buscarSubcategoria->fetch(PDO::FETCH_ASSOC)) {
    $return[] = array(
    'id_subcategoria'   => $linha['id_subcategoria'],
    'subcategoria'  => utf8_encode($linha['subcategoria']),
);
}
echo json_encode($return);
    
asked by anonymous 29.12.2015 / 12:12

0 answers