2014-07-23 108 views
0

我有一個顯示SQL查詢結果(針對Oracle DB)的問題。我的網頁代碼如下。我正在使用tnsnames並在oracle數據庫服務器本身上運行web服務器和頁面。在sqlplus/sql開發者中運行查詢可以正常工作。PHP Oracle顯示結果

TNSNAMES:

testdb = 
    (DESCRIPTION = 
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.101)(PORT = 1521)) 
    (CONNECT_DATA = 
     (SERVER = DEDICATED) 
     (SERVICE_NAME = testdb) 
    ) 
) 

頁面顯示2個變量,之後直接腳註。

如何顯示返回的數據?有人能幫幫我嗎?

感謝

<head> 
    <title>Reports</title> 
    <link href="Site.css" rel="stylesheet"> 
</head> 

<body> 
    <?php include("Header.php"); ?> 
    <div id="main"> 
    <h1>Report1</h1> 
    <h2>Report2</h2> 
    <p>Report3</p> 

    <?php 

    if (isset($_GET['var1'])) { 
    $var_storenr = $_GET['var1']; 
    } 

    if (isset($_GET['var2'])) { 
    $var_storearea = $_GET['var2']; 
    } 

    echo "<p>Var 1: " . $var_storenr . "</p>"; 
    echo "<p>Var 2: " . $var_storearea . "</p>"; 

    $db_user='testusr'; 
    $db_pass='testusr'; 
    $db_name='testdb'; 
    $conn = oci_connect($db_user, $db_pass, $db_name); 
    $query = 'select id_store, store_des from np_stores where id_store in ('.$var_storenr.') and id_region = '.$var_storearea.';'; 

    if (!$conn) { 
     $e = oci_error(); 
     trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); 
    } 

    $stid = oci_parse($conn, $query); 
    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) : "&nbsp;") . "</td>\n"; 
     } 
     echo "</tr>\n"; 
    } 
    echo "</table>\n"; 

    ?> 

    <?php include("Footer.php"); ?> 
    </div> 
    </body> 

回答

0

我已經想通了。這是oracle連接的問題,主要是PHP和x64 Oracle客戶端。

安裝了x32客戶端,工作正常。

謝謝,