xref: /PHP-8.1/ext/oci8/tests/lob_018.phpt (revision b5a14e6c)
1--TEST--
2fetching the same lob several times
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
8require(__DIR__.'/skipif.inc');
9?>
10--FILE--
11<?php
12
13require(__DIR__.'/connect.inc');
14
15// Initialization
16
17$stmtarray = array(
18    "drop table lob_018_tab",
19    "create table lob_018_tab (mykey number, lob_1 clob)",
20);
21
22oci8_test_sql_execute($c, $stmtarray);
23
24echo "Test 1\n";
25
26$init = "insert into lob_018_tab (mykey, lob_1) values(1, empty_clob()) returning lob_1 into :mylob";
27$statement = oci_parse($c, $init);
28$clob = oci_new_descriptor($c, OCI_D_LOB);
29oci_bind_by_name($statement, ":mylob", $clob, -1, OCI_B_CLOB);
30oci_execute($statement, OCI_DEFAULT);
31$clob->save("data");
32
33oci_commit($c);
34
35$init = "insert into lob_018_tab (mykey, lob_1) values(2, empty_clob()) returning lob_1 into :mylob";
36$statement = oci_parse($c, $init);
37$clob = oci_new_descriptor($c, OCI_D_LOB);
38oci_bind_by_name($statement, ":mylob", $clob, -1, OCI_B_CLOB);
39oci_execute($statement, OCI_DEFAULT);
40$clob->save("long data");
41
42oci_commit($c);
43
44
45$query = 'select * from lob_018_tab order by mykey asc';
46$statement = oci_parse ($c, $query);
47oci_execute($statement, OCI_DEFAULT);
48
49while ($row = oci_fetch_array($statement, OCI_ASSOC)) {
50    $result = $row['LOB_1']->load();
51    var_dump($result);
52}
53
54echo "Test 2\n";
55
56$query = 'select * from lob_018_tab order by mykey desc';
57$statement = oci_parse ($c, $query);
58oci_execute($statement, OCI_DEFAULT);
59
60while ($row = oci_fetch_array($statement, OCI_ASSOC)) {
61    $result = $row['LOB_1']->load();
62    var_dump($result);
63}
64
65echo "Test 3 - bind with SQLT_CLOB (an alias for OCI_B_CLOB)\n";
66
67$init = "insert into lob_018_tab (mykey, lob_1) values(3, empty_clob()) returning lob_1 into :mylob";
68$statement = oci_parse($c, $init);
69$clob = oci_new_descriptor($c, OCI_D_LOB);
70oci_bind_by_name($statement, ":mylob", $clob, -1, SQLT_CLOB);
71oci_execute($statement, OCI_DEFAULT);
72$clob->save("more stuff");
73
74oci_commit($c);
75
76$query = 'select * from lob_018_tab where mykey = 3';
77$statement = oci_parse ($c, $query);
78oci_execute($statement, OCI_DEFAULT);
79
80while ($row = oci_fetch_array($statement, OCI_ASSOC)) {
81    $result = $row['LOB_1']->load();
82    var_dump($result);
83}
84
85// Cleanup
86
87$stmtarray = array(
88    "drop table lob_018_tab"
89);
90
91oci8_test_sql_execute($c, $stmtarray);
92
93?>
94--EXPECT--
95Test 1
96string(4) "data"
97string(9) "long data"
98Test 2
99string(9) "long data"
100string(4) "data"
101Test 3 - bind with SQLT_CLOB (an alias for OCI_B_CLOB)
102string(10) "more stuff"
103