2

我有一个 PHP 脚本来从 Oracle SQL 中获取数据。我需要在 HTML 代码中包含 fetch 语句。基本上我想在 PHP 标记中处理所有与 PHP 相关和数据库相关的查询,在需要的地方,我可以从数组中获取结果,而不是再次包含 oci_fetch() 和 oci_result 语句。

例如,

<?php
/* Database Connection*/

if(!$dbConn = oci_connect('WHSUSR','goldeneyex','MyServer.biz:1530/OSLTP')){
    $err = oci_error();
    trigger_error('Could not establish a connection: ' . $err['message'], E_USER_ERROR);
};

/* Query to get Users last accessed appication */
$strSQLUserLogInDetails = "select v.user_name,  max(start_time) from sessiont s inner join V_BO_USER_CODES v on v.user_obj_id = s.user_id
                                    where v.user_name not in ('KALIDO MDM Anonymous User', 'KALIDO MDM Publication Service User')
                            group by v.user_name
                            order by 2 desc";

$stmtUserLogInDetails = oci_parse($dbConn,$strSQLUserLogInDetails);
if ( ! oci_execute($stmtUserLogInDetails) ){
    $err = oci_error($stmtUserLogInDetails);
    trigger_error('Query failed: ' . $err['message'], E_USER_ERROR);
};
?>

和下面的HTML代码...

<table class="table table-striped" title="List of Users who last accessed Kalido application">
    <thead><tr><th>User Name</th><th>Last Accessed On</th></tr></thead>
    <tbody>                     
        <?php
            while(oci_fetch($stmtUserLogInDetails)){
                $uname = oci_result($stmtUserLogInDetails, 1);
                $datetime = oci_result($stmtUserLogInDetails, 2);
                print "<tr><td><a href='userlevelreport.php?uname=".$uname."'>" .$uname. "</a></td><td>".$datetime."</td></tr>";
            }
        ?>
    </tbody>
</table>
4

2 回答 2

1

使用函数oci-fetch-array

在该链接上,您有一些如何使用它的示例。

在您的特定情况下:

...

$rows = array();
if ( ! oci_execute($stmtUserLogInDetails) ){
    $err = oci_error($stmtUserLogInDetails);
    trigger_error('Query failed: ' . $err['message'], E_USER_ERROR);
}
else
{
    while ($row = oci_fetch_array($stid, OCI_ASSOC)) {
        $rows[] = $row; 
    }
}

$rows 将包含一个包含结果的数组。

于 2013-05-24T15:59:06.360 回答
0

您可以使用此功能:

oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)
于 2013-05-24T15:52:10.400 回答