我有一个 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>