Home php教程 php手册 带Oracle数据库分页显示功能的留言簿(3)

带Oracle数据库分页显示功能的留言簿(3)

Jun 21, 2016 am 09:08 AM
cursor oracle

oracle|分页|数据|数据库|显示

程序分成四部份

  1.. 初始化

  2.. 取数据库中的数据

  3.. 计算要显示的页数

  4.. 送出资料

  这个程序在 BIGLOBE 上有实作,由于这是一间 ISP 公司,因此在设定时限定连结或专线的会员才能看到,进入前要输入帐号及密码。为了保护留言者的隐私,留言以马赛克处理。

$WebmasterIPArray = array(
"10.0.1.30", // 管理人员甲的机器 IP
"10.0.2.28" // 管理人员乙的机器 IP
);

$WebmasterIP=false;
for ($i=0; $i<Count($WebmasterIPArray); $i++) {
if ($REMOTE_ADDR == $WebmasterIPArray[$i]) $WebmasterIP=true;
}
// 之后初始化 Oracle 程序略

  显示程序和留言程序的初始化部份都差不多,但显示程序多加了一个功能,设定Webmaster 的电脑。将 Webmaster 使用的 IP Address 加在 $WebmasterIPArray 阵列变数中,可以在显示留言时,显示删除留言的字串,方便处理不当的留言。

$handle=ora_logon("user38@WWW","iam3849") or die;
$cursor=ora_open($handle);
ora_commitoff($handle);

$query="SELECT serial, ref, id, alias, ip, TO_CHAR(msgdate,
'yyyy/mm/dd hh:mi:ss'), email, msg FROM guestbook where flag='1' order by
msgdate desc";
ora_parse($cursor, $query) or die;
ora_exec($cursor);
$i=0;
while(ora_fetch($cursor)) {
$guestbook[$i][0] = ora_getcolumn($cursor,0);
$guestbook[$i][1] = ora_getcolumn($cursor,1);
$guestbook[$i][2] = ora_getcolumn($cursor,2);
$guestbook[$i][3] = ora_getcolumn($cursor,3);
$guestbook[$i][4] = ora_getcolumn($cursor,4);
$guestbook[$i][5] = ora_getcolumn($cursor,5);
$guestbook[$i][6] = ora_getcolumn($cursor,6);
$guestbook[$i][7] = ora_getcolumn($cursor,7);
$i++;
}
ora_close($cursor);
ora_logoff($handle);

  在初始化后,就可以连上 Oracle 资料库,将留言的资料取出放在 $guestbook阵列中。取得资料后,就赶紧将资料库关闭,再来处理 $guestbook 阵列的资料了。

if ($QUERY_STRING!="") {
$page = $QUERY_STRING;
} else {
$page = 0;
}

  这一段程序判断是要显示第几页,内定值是显示第一页。要显示第三页的页面,需要使用 http://xxxxxx/index.php?2 的格式,也就是传入 $QUERY_STRING,余类推。之后的数行程序,都是用来处理显示的页数及笔数的资料。

$msgnum=20; // 每页二十笔

  要改变每页的显示笔数,可以改 $msgnum 变数。程序的内定值为 20 笔。

for ($i=$start; $i<$end; $i++) {
echo "<p><hr><p>\n";
echo "<p>\n<font color=e06060>".$guestbook[$i][5]."</font>   ";
if ($guestbook[$i][6]!="") echo "<a
href=mailto:".$guestbook[$i][6].">";
echo "<strong>".$guestbook[$i][3]."</strong>";
if ($guestbook[$i][6]!="") echo "</a>";
echo "<br>\n";
if ($WebmasterIP) echo "<a href=erase.php?".$guestbook[$i][0].">删除
本篇!!</a> (".$guestbook[$i][2].")   ";
echo "<font size=-1 color=c0c0c0>from:
".$guestbook[$i][4]."</font><p>\n";
$msg=base64_decode($guestbook[$i][7]);
$msg=nl2br($msg);
echo $msg;
echo "<p>\n";
}

  这一段程序就是真正显示留言资料给使用者看的程序了。利用 for 回圈,将$guestbook 阵列的资料按照设定的页数取出,显示给使用者看。值得一提的是,若看留言的机器 IP 为 $WebmasterIPArray 变数阵列中的一个元素的话,则会在留言者的匿称后显示 "删除本篇!!" 的字串,供管理人员删除不当留言。

  以下即为删除留言的程序。

<?php
file://---------------------------
// 留言删除程序 erase.php
// Author: Wilson Peng
// Copyright (C) 2000
file://---------------------------
putenv("ORACLE_SID=WWW");
putenv("NLS_LANG=american_taiwan.zht16big5");
putenv("ORACLE_HOME=/home/oracle/product/7.3.2");
putenv("LD_LIBRARY_PATH=/home/oracle/product/7.3.2/lib");

putenv("ORA_NLS=/home/oracle/product/7.3.2/ocommon/nls/admin/data");

putenv("ORA_NLS32=/home/oracle/product/7.3.2/ocommon/nls/admin/data");

$handle=ora_logon("user38@WWW","iam3849") or die;
$cursor=ora_open($handle);
ora_commitoff($handle);

$query="UPDATE guestbook set flag='0' where
serial='".$QUERY_STRING."'";
ora_parse($cursor, $query) or die;
ora_exec($cursor);

ora_close($cursor);
ora_logoff($handle);

Header("Location: ./index.php");
?>

  其实这个程序很单纯,只要打开 Oracle 资料库,将欲删除的序号那笔资料的flag 栏位设成 0 就可以了,不用将资料真的从资料库上移除。



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1263
29
C# Tutorial
1237
24
What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

How to export oracle view How to export oracle view Apr 12, 2025 am 06:15 AM

Oracle views can be exported through the EXP utility: Log in to the Oracle database. Start the EXP utility, specifying the view name and export directory. Enter export parameters, including target mode, file format, and tablespace. Start exporting. Verify the export using the impdp utility.

See all articles