各位尊敬的高手懇請幫忙
請問以下程式碼無法抓到TABLE資料,帳號、密碼、IP都沒有問題輸出卻無法帶出資料
OS : CENTOS 7
PHP 7.3.4
遠端ORACLE 10g
程式碼:
$conn = OCILogon('ID','PW','172.x.x.x/DB');
$sql = oci_query("Select azk01,to_char(azk02,'yyyy/mm/dd') azk02,azk03,azk04,azk051,azk052 from ds11.azk_file,ds11.azi_file Where azk01=azi01 and to_char(azk02,'yyyymmdd')=to_char(sysdate,'yyyymmdd') order by azk01 desc ");
$datarow = oci_num_rows($sql);
for($i=0;$i<$datarow;$i++){
$sql_arr = oci_fetch_assoc($sql);
$AZK01 = $sql_arr['AZK01'];
$AZK03 = $sql_arr['AZK03'];
$AZK04 = $sql_arr['AZK04'];
$AZK051 = $sql_arr['AZK51'];
$AZK052 = $sql_arr['AZK052'];
echo "<tr><td>$AZK01</td><td>$AZK03</td><td>$AZK04</td><td>$AZK051</td><td>$AZK052</td></tr>
輸出結果: (目前錯誤圖)
目標結果:(希望正確圖)
請各位高手幫幫忙,不足之處再請告知
感謝
用oci_execute的範例修改如下
試試看 work 不 work
<?php
$conn = OCILogon('ID','PW','172.x.x.x/DB');
$sql = oci_query("Select azk01,to_char(azk02,'yyyy/mm/dd') azk02,azk03,azk04,azk051,azk052 from ds11.azk_file,ds11.azi_file Where azk01=azi01 and to_char(azk02,'yyyymmdd')=to_char(sysdate,'yyyymmdd') order by azk01 desc ");
$stid = oci_parse($conn, $sql);
oci_execute($stid);
echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
?>
先能抓到資料
格式再慢慢調整
謝謝海綿寶寶,我再努力嘗試一下
海綿寶寶大大以下測試OK~感謝
<?php
$conn= oci_connect('ID', 'PW', '172.x.x.x:1521/DB','AL32UTF8');
if($conn) {
echo"今日匯率";
}else{
echo"連接oracle失敗!";
exit;
}
$stid = oci_parse($conn, "Select azk01,to_char(azk02,'yyyy/mm/dd') azk02,azk03,azk04,azk051,azk052 from ds11.azk_file,ds11.azi_file Where azk01=azi01 and to_char(azk02,'yyyymmdd')=to_char(sysdate,'yyyymmdd') order by azk01 desc");
oci_execute($stid);
echo "<table border='1'";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>";
foreach ($row as $item) {
echo "<td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "") . "
</td>";
}
}
?>