1
2 <?php
3 /* OCIBindByPos の例 thies@digicol.de (980221)
4
5 3 レコードを emp に挿入し、挿入の直後にレコードを更新するために ROWID を使用します。
6 */
7
8 $conn = OCILogon("scott","tiger");
9
10 $stmt = OCIParse($conn,"insert into emp (empno, ename) ".
11 "values (:empno,:ename) ".
12 "returning ROWID into :rid");
13
14 $data = array(1111 => "Larry", 2222 => "Bill", 3333 => "Jim");
15
16 $rowid = OCINewDescriptor($conn,OCI_D_ROWID);
17
18 OCIBindByName($stmt,":empno",&$empno,32);
19 OCIBindByName($stmt,":ename",&$ename,32);
20 OCIBindByName($stmt,":rid",&$rowid,-1,OCI_B_ROWID);
21
22 $update = OCIParse($conn,"update emp set sal = :sal where ROWID = :rid");
23 OCIBindByName($update,":rid",&$rowid,-1,OCI_B_ROWID);
24 OCIBindByName($update,":sal",&$sal,32);
25
26 $sal = 10000;
27
28 while (list($empno,$ename) = each($data)) {
29 OCIExecute($stmt);
30 OCIExecute($update);
31 }
32
33 $rowid->free();
34
35 OCIFreeStatement($update);
36 OCIFreeStatement($stmt);
37
38 $stmt = OCIParse($conn,"select * from emp where empno in (1111,2222,3333)");
39 OCIExecute($stmt);
40 while (OCIFetchInto($stmt,&$arr,OCI_ASSOC)) {
41 var_dump($arr);
42 }
43 OCIFreeStatement($stmt);
44
45 /* テーブル emp から "junk" を削除する.... */
46 $stmt = OCIParse($conn,"delete from emp where empno in (1111,2222,3333)");
47 OCIExecute($stmt);
48 OCIFreeStatement($stmt);
49
50 OCILogoff($conn);
51 ?> |