0
連接到MSSQLPHP + Mssql中不顯示結果
session_start();
// CONEXION
$link = mssql_connect('xxx.xxx.xx.xx', 'xxx', 'xxx');
mssql_select_db("xxx",$link);
if (!$link || !mssql_select_db('BDFlexline', $link)) {
die('No se puede conectar o seleccionar una base de datos!');
}
// FIN CONEXION
if(isset($_GET["dcto"])){
$dcto = $_GET["dcto"];
$empresa = $_GET['empresa'];
}
查詢這裏
$conn ="SELECT
D.TIPODOCTO, d.CORRELATIVO, d.CLIENTE,coalesce(c.razonsocial,'') RAZONSOCIAL,
v.DESCRIPCION as VENDEDOR , D.NUMERO, D.FECHA, D.TOTAL, d.Local as CLUB
from documento D
left join Vendedor v on d.Empresa = v.EMPRESA and d.Vendedor = v.CODIGO
left join ctacte c on c.empresa=d.empresa and c.tipoctacte=d.tipoctacte and c.ctacte =d.idctacte
where d.total >= 0
and d.aprobacion not in ('S','N')
and d.tipodocto='".$dcto."'
and d.empresa='".$empresa."'
and d.vigencia not in ('N','A')
and d.Fecha between CONVERT(VARCHAR(25), DATEADD(mm, -1, DATEADD(dd,-(DAY(GETDATE())-1),GETDATE())),105)
and CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,GETDATE()))),DATEADD(mm,1,GETDATE())),105)
order by d.numero";
查詢就可以了,工作從SQL Management Console中預期的,但是PHP ...
$result= mssql_query($conn, $link);
############# PRUEBA 1 #################
$json = array();
do {
while ($row = mssql_fetch_object($result)){
$json[] = $row;
}
}while (mssql_next_result($result));
echo json_encode($json);
mssql_close($link);
結果是[]但是必須是:
[{"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"},
{"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"}] .... and more
我需要的結果以JSON格式東陽使用im angularJS。 感謝您的任何想法
感謝Thread7, EDITED: 康恩=選擇D.TIPODOCTO,d.CORRELATIVO,d.CLIENTE,聚結(c.razonsocial, '')RAZONSOCIAL,v.DESCRIPCION如VENDEDOR,D.NUMERO,D.日期星,D.TOTAL,d.Local從這份執行d CLUB左加入上d.Empresa = v.EMPRESA和d.Vendedor = v.CODIGO Vendedor v左加入上c.empresa = d.empresa和c.tipoctacte ctacteç = d.tipoctacte和c.ctacte = d.idctacte其中d.total> = 0,而不是在( 'S', 'N')和d.tipodocto = 'COTIZACION' 和d.empresa d.aprobacion = 'E01' ... 查詢好看,這個問題也許是mssql_fetch_object –
並在控制檯顯示數據的查詢,但沒有在PHP –
它實際上是進入while循環?放一個回聲「Inside While Loop」;看看。如果沒有,那麼也許出錯了$鏈接或mssql_select_db聲明。另一個嘗試是一個非常簡單的查詢。像$ conn =「select * from documento」;如果這不產生任何結果,那麼顯然與查詢無關。最後,什麼版本的PHP? mssql_fetch_object被棄用,從PHP 7除去。 – Thread7