PHP 매뉴얼
이전 |  | 다음

# OCINewCursor

(PHP 3>= 3.0.8, PHP 4 , PHP 5)

OCINewCursor -- 새로운 커서(구문 핸들)를 리턴한다 - ref-cursor를 연계하기위함.

## Description

int OCINewCursor ( int conn)

OCINewCursor()함수는 특정 접속점에 관한 새로운 구문 핸들을 할당한다.

예 1. 스토어드 프로시저에 REF CURSOR 사용하기

    <?php
    // suppose your stored procedure info.output returns a ref cursor in :data

    $conn = OCILogon("scott","tiger");
    $curs = OCINewCursor($conn);
    $stmt = OCIParse($conn,"begin info.output(:data); end;");

    ocibindbyname($stmt,"data",&amp;$curs,-1,OCI_B_CURSOR);
    ociexecute($stmt);
    ociexecute($curs);

    while (OCIFetchInto($curs,&amp;$data)) {
        var_dump($data);
    }

    OCIFreeCursor($stmt);
    OCIFreeStatement($curs);
    OCILogoff($conn);
    ?>

예 2. SELECT 구문에 REF CURSOR 사용하기

    <?php
    print "<HTML><BODY>";
    $conn = OCILogon("scott","tiger");
    $count_cursor = "CURSOR(select count(empno) num_emps from emp " .
                    "where emp.deptno = dept.deptno) as EMPCNT from dept";
    $stmt = OCIParse($conn,"select deptno,dname,$count_cursor");

    ociexecute($stmt);
    print "<TABLE BORDER=\"1\">";
    print "<TR>";
    print "<TH>DEPT NAME</TH>";
    print "<TH>DEPT #</TH>";
    print "<TH># EMPLOYEES</TH>";
    print "</TR>";

    while (OCIFetchInto($stmt,&amp;$data,OCI_ASSOC)) {
        print "<TR>";
        $dname  = $data["DNAME"];
        $deptno = $data["DEPTNO"];
        print "<TD>$dname</TD>";
        print "<TD>$deptno</TD>";
        ociexecute($data[ "EMPCNT" ]);
        while (OCIFetchInto($data[ "EMPCNT" ],&amp;$subdata,OCI_ASSOC)) {
            $num_emps = $subdata["NUM_EMPS"];
            print  "<TD>$num_emps</TD>";
        }
        print "</TR>";
    }
    print "</TABLE>";
    print "</BODY></HTML>";
    OCIFreeStatement($stmt);
    OCILogoff($conn);
    ?>

이전 | 처음으로 | 다음
ocinewcollection | 위로 | OCINewDescriptor