Serialize the result of a JSON query?

Asked

Viewed 99 times

0

I am adding the result of a query to an array and am trying to serialize to Json. I’m not getting my printing right JSON, could help me?

My code:

<?php

ini_set('max_execution_time', 123456);

$conn = oci_connect('teste', 'teste123', '192.168.90.3/teste');

if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$query = oci_parse($conn, 'SELECT NR_SEQUENCIA, DS_GRUPO_TRABALHO FROM man_grupo_trabalho');
oci_execute($query);

$rows = array();
while($r = oci_fetch_assoc($query)) {
$rows[] = $r;
 }
$locations =(json_encode($rows));
echo $locations;

?>

But it’s generating the error:

Warning: oci_connect(): in C: xampp htdocs billing.php on line 5

Fatal error: in C: xampp htdocs billing.php on line 9

  • 1

    What’s the matter? you want to print json?

  • 1

    At least in this code it does not print the json, I suggest, remove echo 'done!'; and add echo $locations;

  • I removed according to the last history but still gave error: Warning: oci_connect(): in C: xampp htdocs billing connection.php on line 5 Fatal error: in C: xampp htdocs billing connection.php on line 9

  • 1

    But that there seems to be error of the query, you can make a simple example p test the json, create a new file with that code <?php json_encode(array('msg' => 'teste', 'data' => date('H:i:s')));

  • Actually the connection data in the publication was wrong. I already changed but the internet browser stopped printing the word done and started to assume empty, IE, page without result

  • 1

    If you throw this query straight into the oracle of some error?

  • what query? SELECT NR_SEQUENCIA, DS_GRUPO_TRABALHO FROM man_group_work

  • That same query, of the error in the bank?

  • The result looks normally in the oracle database, ie, I view all the records of the table

  • see if this returns the error message oci_execute($query) or die(print_r(oci_error($conn)));

  • Page still no result, even adding this last code

  • seems to have nothing to do with json... the error message is clear about the error in connection with oracle... fix this which will probably work the rest.

Show 7 more comments

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.