0

what's wrong in my code? i cant show the data in json...

here's my code..

i'm using oracle with adodb

 function getDados(){
    try{
        $sql = "SELECT * FROM TMP0145705";
        $db = getDB();

        if($db){
            $stmt = $db->Execute($sql);

            $ret = array();
            /*while ($arr = $stmt->FetchRow()) {
                print_r($arr);
                echo "<hr>";
            }*/
            while(!$stmt->EOF){
                $ret[] = $stmt->fields;
                $stmt->MoveNext();
            }
            echo '{"ret": ' . json_encode($ret) . '}';    
        }
        $db = null;
    }catch(Exception $e){
        echo '{"error":{"text":'. $e->getMessage() .'}}';
    }
}

edit:

my json:

{"ret": }

edit:

print_r($ret);

Array ( [0] => Array ( [0] => [MANAGERS] => [1] => 1 [FACTORY] => 1 [2] => 1 [PRODUCT] => 1 [3] => 174))

edit:

 $ret = $stmt->GetArray();

            var_dump($ret);
            echo '{"ret": ' . json_encode($ret) . '}';    

            if( $jret = json_encode($ret) ){ echo "nice"; } else{ echo "Fail"; }

solution!:

my data is in utf-08 and for some reason the json cannot accept that...

how can i resolve that?

novato
  • 153
  • 1
  • 1
  • 8
  • do you need the array inside the array, and have you verified that the query is returning data? – Doon May 12 '16 at 19:38
  • yes.. its returning data.. i test with print_r... – novato May 12 '16 at 19:40
  • Questions seeking debugging help ("**why isn't this code working?**") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Pedro Lobito May 12 '16 at 19:41
  • Can you show us the print_r or var_dump of `$ret`? – Chin Leung May 12 '16 at 19:42
  • sure... check my edit – novato May 12 '16 at 19:45
  • I've had this happen if json_encode is not able to successfully encode the array. [Turn on error reporting](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) or just check if json_encode worked: `if( $jret = json_encode($ret) ){ echo ... } else{ echo "Fail"; }` – Dan May 12 '16 at 19:46
  • dan08... i've checked and is returning "Fail" – novato May 12 '16 at 19:51
  • Ok, so you have to check the error (it won't be obvious) and figure why your array is giving json_encode a problem. `var_dump` will be more helpful than `print_r` for the trouble shooting – Dan May 12 '16 at 19:54
  • i dont have idea... i've changed the code.. but same problem.. – novato May 12 '16 at 20:04
  • pump your json through a json validator and make sure it's valid. – VikingBlooded May 12 '16 at 20:34

0 Answers0