0
good afternoon,
the following code returns me in json... but is in Pdo.. as would be in adodb?
$users = $stmt->fetchAll(PDO::FETCH_OBJ);
echo '{"users": ' . json_encode($users) . '}';
Edit:
I tried this, but it doesn’t work:
if($db){
$stmt = $db->Execute($sql);
$retorno = array();
while(!$stmt->EOF){
$retorno[] = $stmt->fields;
$stmt->MoveNext();
}
echo '{"retorno": ' . json_encode($retorno) . '}';
}
What I tried to do in the above code was to go through the recordset with the select data by inserting this data into the array. and turn the array into json..
returns the empty json.. but the query, by the test I did, returns data
json result:
{"retorno": }
print_r result($return);
Array ( [0] => Array ( [0] => [VENDA] => [1] => 1 [PRODUTO] => 1 ) )
Edit:
if($db){
$stmt = $db->Execute($sql);
$retorno = array();
while($res = $stmt->GetArray()){
$retorno[] = $res;
}
echo '{"retorno": ' . json_encode($retorno) . '}';
}
solution!
if($db){
$stmt = $db->Execute($sql);
$retorno = $stmt->GetArray();
//var_dump($retorno);
echo '{"retorno": ' . json_encode($retorno) . '}';
if( $jret = json_encode($retorno) ){ echo "nice"; } else{ echo "Fail"; }
}
however... my data has a special character like "ç" and json is not accepting this.. i.e. it is not accepting utf-08.. when I remove the special characters json works...
Somebody knows how to fix this?
creates a loop and assigns the array after it
echo json_encode($dados);
if I’m not mistaken ADOBD uses a méotodosnext()
and the propsEOF
orBOF
– rray
Does an error appear? more specifically what would 'not work'?
– rray
Could put the result of:
print_r($retorno)
in the question.– rray