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