没有显示正确的信息PHP和Oracle查询

问题描述 投票:1回答:1

我的问题是关于一个可以与PHP连接的Oracle数据库。使用SQL Developer进行相同的查询我得到了这个:

introducir la descripción de la imagen aquí

但是在PHP中:

$tsql= "select orden, fase, maquina_id, DescMaterial, dhsalida, scg_MaterialesLotes.lote, scg_MaterialesLotes.lotecli from scg_fases inner join scg_materiales on scg_fases.IdBoletin = scg_Materiales.IdBoletin inner join scg_MaterialesLotes on scg_Materiales.IdMatOf = scg_MaterialesLotes.IdMatOF";

$stmt = sqlsrv_query( $conn, $tsql);  

if ( $stmt )    
{ 
  ?>

  while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))
  {
    $orden = $row["orden"];
    $fase = $row["fase"];
    $puesto = $row["maquina_id"];
    $art = $row["CodMaterial"];
    $desc = $row["DescMaterial"];
    $fecha = $row["dhsalida"];
    $lote = $row["scg_MaterialesLotes.lote"];
    $loteCli = $row["scg_MaterialesLotes.lotecli"];

    echo "<tr>";
    echo "<td align=center>" . $orden . "</td>";
    echo "<td align=center>" . $fase . "</td>";
    echo "<td align=center>" . $puesto . "</td>";
    echo "<td align=center>" . $art . "</td>";
    echo "<td align=center>" . $desc . "</td>";
    echo "<td align=center>" . $fecha . "</td>";
    echo "<td align=center>" . $lote . "</td>";
    echo "<td align=center>" . $loteCli . "</td>";
    echo "</tr>";
  }

  ?>
  </table>
  </body>
  </html>
  <?php
}     
else     
{    
  echo "Submission unsuccessful.";
  die( print_r( sqlsrv_errors(), true));    
} 

sqlsrv_free_stmt( $stmt);    
sqlsrv_close( $conn);

使用浏览器显示:

introducir la descripción de la imagen aquí

为什么我不能显示相同的信息?问题出在哪儿?谢谢

php oracle oracle-sqldeveloper
1个回答
1
投票

1)将CodMaterial字段添加到您的查询中您不在查询中包含字段CodMaterial,因此这一行:

$art = $row["CodMaterial"];

什么也没做。因此,您可以将此字段添加到查询中的长字段列表中,或者只使用SELECT * FROM...检索每个字段。

2)不要在查询结果行中使用tablename.columnname例如,当您查询scg_MaterialesLotes.lote时,结果属性将被称为lote,因此不要在PHP代码中使用它:

$lote = $row["scg_MaterialesLotes.lote"];

用这个:

$lote = $row["lote"];

scg_MaterialesLotes.lotecli做同样的事情

3)Echo $fecha作为一个字符串,此刻是一个类型的对象而不是使用:

echo "<td align=center>" . $fecha . "</td>";

请改用:

echo "<td align=center>" . ($fecha ? $fecha->format("Y-m-d H:i:s") : ""). "</td>";

© www.soinside.com 2019 - 2024. All rights reserved.