xref: /PHP-8.1/ext/oci8/tests/bind_rowid.phpt (revision 74859783)
1--TEST--
2Test ROWID bind
3--EXTENSIONS--
4oci8
5--FILE--
6<?php
7
8require(__DIR__."/connect.inc");
9
10function do_query($c)
11{
12    $s = oci_parse($c, 'select address from rid_tab order by id');
13    $id = 1;
14    oci_execute($s, OCI_DEFAULT);
15    while ($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) {
16        var_dump($row);
17    }
18}
19
20$stmtarray = array(
21    "drop table rid_tab",
22    "create table rid_tab (id number, address varchar2(40))",
23    "insert into rid_tab (id, address) values (1, 'original text #1')",
24    "insert into rid_tab (id, address) values (2, 'original text #2')"
25);
26
27oci8_test_sql_execute($c, $stmtarray);
28
29echo "Initial Data\n";
30do_query($c);
31
32$s = oci_parse($c, 'select rowid, address from rid_tab where id = :l_bv for update');
33$id = 1;
34oci_bind_by_name($s, ':l_bv', $id);
35oci_execute($s, OCI_DEFAULT);
36$row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS);
37
38$rid = $row['ROWID'];
39$addr = $row['ADDRESS'];
40
41$addr = 'Some new text';
42
43// Save changes
44$s = oci_parse($c,'update rid_tab set address = :a_bv where rowid = :r_bv');
45oci_bind_by_name($s, ':r_bv', $rid, -1, OCI_B_ROWID);
46oci_bind_by_name($s, ':a_bv', $addr);
47oci_execute($s);
48
49echo "Verify Change\n";
50do_query($c);
51
52// Cleanup
53
54$stmtarray = array(
55    "drop table rid_tab"
56);
57
58oci8_test_sql_execute($c, $stmtarray);
59
60echo "Done\n";
61
62?>
63--EXPECT--
64Initial Data
65array(1) {
66  ["ADDRESS"]=>
67  string(16) "original text #1"
68}
69array(1) {
70  ["ADDRESS"]=>
71  string(16) "original text #2"
72}
73Verify Change
74array(1) {
75  ["ADDRESS"]=>
76  string(13) "Some new text"
77}
78array(1) {
79  ["ADDRESS"]=>
80  string(16) "original text #2"
81}
82Done
83