通过缓存数据库结果提高PHP性能(2)
创建通知处理程序
现在,您可以创建一个通知处理程序,它将借助于上面介绍的 sendNotification
过程向客户端发送更改通知。来看一看“清单 2”中的 PL/SQL 过程 orders_nf_callback。
清单 2.
处理对 OE.ORDERS 表所做更改的通知的通知处理程序
CREATE OR REPLACE PROCEDURE orders_nf_callback (ntfnds IN SYS.CHNF$_DESC) IS <br>tblname VARCHAR2(60); <br>numtables NUMBER; <br>event_type NUMBER; <br>row_id VARCHAR2(20); <br>numrows NUMBER; <br>ord_id VARCHAR2(12); <br>url VARCHAR2(256) := 'http://webserverhost/phpcache/dropResults.php?order_no='; <br>BEGIN <br>event_type := ntfnds.event_type; <br>numtables := ntfnds.numtables; <br>IF (event_type = DBMS_CHANGE_NOTIFICATION.EVENT_OBJCHANGE) THEN <br>FOR i IN 1..numtables LOOP <br>tblname := ntfnds.table_desc_array(i).table_name; <br>IF (bitand(ntfnds.table_desc_array(i).opflags, <br>DBMS_CHANGE_NOTIFICATION.ALL_ROWS) = 0) THEN <br>numrows := ntfnds.table_desc_array(i).numrows; <br>ELSE <br>numrows :=0; <br>END IF; <br>IF (tblname = 'OE.ORDERS') THEN <br>FOR j IN 1..numrows LOOP <br>row_id := ntfnds.table_desc_array(i).row_desc_array(j).row_id; <br>SELECT order_id INTO ord_id FROM orders WHERE rowid = row_id; <br>sendNotification(url, tblname, ord_id); <br>END LOOP; <br>END IF; <br>END LOOP; <br>END IF; <br>COMMIT; <br>END; <br>/ <br>如“清单 2”所示,此通知处理程序将 SYS.CHNF$_DESC
对象用作参数,然后使用它的属性获取该更改的详细信息。在该示例中,此通知处理程序将只处理数据库为响应对注册对象进行的 DML 或 DDL
更改(也就是说,仅当通知类型为 EVENT_OBJCHANGE
时)而发布的通知,并忽略有关其他数据库事件(如实例启动或实例关闭)的通知。从以上版本开始,处理程序可以处理针对 OE.ORDERS
表中每个受影响的行发出的更改通知。在本文后面的“将表添加到现有注册”部分中,您将向处理程序中添加几行代码,以便它可以处理针对 OE.ORDER_ITEMS
表中被修改的行发出的通知。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver CS6
Visual web development tools
