Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/08/2017, 14:52
Avatar de sebandrescc2
sebandrescc2
 
Fecha de Ingreso: diciembre-2012
Mensajes: 45
Antigüedad: 11 años, 4 meses
Puntos: 0
Cambiar consulta sqlsrv a mssql en json

Hola,
Quiero traerme datos del servidor SQL en formato json para leerlos en AnuglarJS, pero no he podido. En principio ocupaba el módulo pdo_sqlsrv y todo marchaba bien, pero el servidor me exige usar mssql y no he podido traer la información correctamente

asi en pdo_sqlsrv

Código PHP:
Ver original
  1. $result= sqlsrv_query($link, $conn);
  2. ## recorremos todos los registros
  3. $json=array();
  4. do {
  5.         while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
  6.         $json[] = $row;
  7.         }
  8. } while ( sqlsrv_next_result($result) );
  9. echo json_encode($json, true);
  10. ## cerramos la conexion
  11. sqlsrv_free_stmt( $result);


Y aquí mi intento mssql

Código PHP:
Ver original
  1. $result= mssql_query($conn, $link);
  2. ## recorremos todos los registros
  3. $json=array();
  4. do {
  5.         while ($row = mssql_fetch_object($result)) {
  6.         $json[] = $row;
  7.         }
  8. } while ( mssql_next_result($result) );
  9. echo json_encode($json);
  10.  
  11. ## cerramos la conexion

La idea es que me devuelva en este formato JSON:

Código HTML:
Ver original
  1. [{"TIPODOCTO":"COTIZACION","CORRELATIVO":"3059","CLIENTE":"20548547-2","RAZONSOCIAL":"SERVICIOS AIR LMTD","VENDEDOR":"Diana","NUMERO":"0000003079","FECHA":{"date":"2017-07-03 00:00:00.000000","timezone_type":3,"timezone":"Europe\/Berlin"},"TOTAL":"3111964.00000000","CLUB":"ADM"},
  2. {"TIPODOCTO":"COTIZACION","CORRELATIVO":"3062","CLIENTE":"71540800-7","RAZONSOCIAL":"UNIVERSIDAD SAC","VENDEDOR":"Ernesto","NUMERO":"0000003482","FECHA":{"date":"2017-07-05 00:00:00.000000","timezone_type":3,"timezone":"Europe\/Berlin"},"TOTAL":"16670624.00000000","CLUB":"ADM"}]

Espero alguna orientación, gracias
__________________
Aquí voy a escribir mi firma