2016-05-15 47 views
0

這裏是我的代碼,我不知道我錯在這裏做甲骨文選擇用PHP不會顯示

<?php 
$conn=oci_connect("martin","123","localhost/XE"); 
If (!$conn) 
    echo 'Failed to connect to Oracle'; 
else 
    echo 'Succesfully connected with Oracle DB';?> 
<table border="1"> 
    <?php $stid = oci_parse($conn, "select*from MsNama"); 
     oci_execute($stid); 

     while ($row = 
    oci_fetch_array(
     $stid, 
     OCI_ASSOC+OCI_RETURN_NULLS) 
) {?> 
<tr> 
    <td><?php echo $row[0]; ?></td> 
    <td><?php echo $row[1]; ?></td> 
    <td><?php echo $row[2]; ?></td> 
</tr> 
     <?php }?> 

這是我的選擇對Oracle數據庫:

SQL> select * from MsNama 
    2 ; 
NAMA      ANGKA G 
---------------------- -------- - 
martin      1 m 

這是什麼看起來像 this is what's it's look like

我改變了代碼我在互聯網上發現,但仍然不工作

<html> 
<head><title>Oracle demo</title> 
</head> 
<body> 
    <?php 
    $conn=oci_connect("martin","123","localhost/XE"); 
     If (!$conn) 
       echo 'Failed to connect to Oracle'; 
     else 
       echo 'Succesfully connected with Oracle DB'; 

     ?> 
     <table border="1"> 
     <?php  $stid = oci_parse($conn, "select * from MsNama"); 
     oci_execute($stid,OCI_DEFAULT); 

     while (oci_fetch($stid)) { 
      $empno = oci_result($stid, "NAMA"); 
      $ename = oci_result($stid, "angka"); 
      $job  = oci_result($stid, "gender"); 

     ?> 
    <tr> 
     <td><?php echo $empno; ?></td> 
     <td><?php echo $ename;?></td> 
     <td><?php echo $job; ?></td> 
    </tr> 
     <?php }?> 
    </table> 

    </body> 
    </html> 

我試過了,總是沒有結果。沒有顯示

+0

爲什麼沒有'select'和'*'&'from'之間的差距? –

+0

不要緊,我給他們之間的差距,就像你建議 – Martin

+0

做'var_dump($ row);'while循環''看看有什麼輸出? –

回答

0

噢,我的代碼沒有錯,但這裏的代碼和它的工作

<html> 
<head><title>Oracle demo</title></head> 
<body> 
<?php 
$conn=oci_connect("martin","123","localhost/XE"); 
If (!$conn) 
    echo 'Failed to connect to Oracle'; 
else 
    echo 'Succesfully connected with Oracle DB'; 

?> 
<table border="1"> 
<?php  $stid = oci_parse($conn, "select*from MsNama"); 
      $r=oci_execute($stid); 

      while ($row = oci_fetch_array($stid, OCI_BOTH)) {?> 
    <tr> 
     <td><?php echo $row[0]; ?></td> 
     <td><?php echo $row[1]; ?></td> 
     <td><?php echo $row[2]; ?></td> 
    </tr> 
      <?php }?> 
</table> 

</body> 
</html> 

,我忘了提交,所以這個問題.-。沒有結果,我很抱歉