0

I want to create a procedure that can monitor dataguard gap and call it in PHP. I searched on the internet on how to create a simple procedure and I succeeded in creating the procedure, but I failed when I tried to call it from PHP.

Here is my php script:

<?php $conn = oci_connect('moni', 'moni', '192.168.56.104:1556/cocacola') or die; $sql = "call monitor_odg" $stid = oci_parse($conn, $sql); /* Binding Parameters */ 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"; ?>

when i load it, it return error :

Parse error: syntax error, unexpected '$stid' (T_VARIABLE) in C:\xampp\htdocs\monitoring\oracle.php on line 8

How to call it from PHP?

Here is my procedure:

create or replace PROCEDURE monitor_odg IS   c1 SYS_REFCURSOR;   BEGIN OPEN c1 FOR   select ar.inst_id "inst_id",
   ar.dest_id "dest_id",
   ar.status "dest_status",
   ar.destination "destination",
     (select MAX (sequence#) highiest_seq
        from v$archived_log val, v$database vdb
       where     val.resetlogs_change# = vdb.resetlogs_change#
             and thread# = ar.inst_id
             and dest_id = ar.dest_id)
   - NVL (
        (select MAX (sequence#)
           from v$archived_log val, v$database vdb
          where     val.resetlogs_change# = vdb.resetlogs_change#
                and thread# = ar.inst_id
                and dest_id = ar.dest_id
                and standby_dest = 'YES'
                and applied = 'YES'),
        0)
      "applied_gap",
     (SELECT MAX (sequence#) highiest_seq
        from v$archived_log val, v$database vdb
       where     val.resetlogs_change# = vdb.resetlogs_change#
             AND thread# = ar.inst_id)
   - NVL (
        (SELECT MAX (sequence#)
           from v$archived_log val, v$database vdb
          where     val.resetlogs_change# = vdb.resetlogs_change#
                and thread# = ar.inst_id
                and dest_id = ar.dest_id
                and standby_dest = 'YES'),
        0)
      "received_gap",
   NVL (
      (SELECT MAX (sequence#)
         from v$archived_log val, v$database vdb
        where     val.resetlogs_change# = vdb.resetlogs_change#
              and thread# = ar.inst_id
              and dest_id = ar.dest_id
              and standby_dest = 'YES'),
      0)
      "last_received_seq",
   NVL (
      (SELECT MAX (sequence#)
         from v$archived_log val, v$database vdb
        where     val.resetlogs_change# = vdb.resetlogs_change#
              and thread# = ar.inst_id
              and dest_id = ar.dest_id
              and standby_dest = 'YES'
              and applied = 'YES'),
      0)
      "last_applied_seq"   from (SELECT DISTINCT dest_id,
                    inst_id,
                    status,
                    target,
                    destination,
                    error
      from sys.gv_$archive_dest
     where target = 'STANDBY' and STATUS <> 'DEFERRED') ar;   DBMS_SQL.RETURN_RESULT(c1); END monitor_odg;

That procedure I got from the internet, I just paste my script inside it, I don't understand what SYS_REFCURSOR for.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Tigerpig
  • 13
  • 1
  • 4

0 Answers0