xref: /PHP-8.3/ext/oci8/tests/lob_001.phpt (revision a53e5617)
1--TEST--
2oci_lob_write() and friends
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_001_tab",
20    "create table lob_001_tab (id number, b1 blob)",
21);
22
23oci8_test_sql_execute($c, $stmtarray);
24
25echo "Test 1 OCI_B_BLOB bind\n";
26
27$statement = oci_parse($c, "insert into lob_001_tab (id, b1) values (1, empty_blob()) returning b1 into :v_b1 ");
28$blob = oci_new_descriptor($c,OCI_D_LOB);
29var_dump(oci_bind_by_name($statement, ":v_b1", $blob, -1, OCI_B_BLOB));
30oci_execute($statement, OCI_DEFAULT);
31var_dump($blob);
32
33echo "Test 2\n";
34
35var_dump($blob->write("test"));
36var_dump($blob->tell());
37var_dump($blob->seek(10, OCI_SEEK_CUR));
38var_dump($blob->write("string"));
39var_dump($blob->flush());
40
41oci_commit($c);
42
43echo "Test 3\n";
44
45$s = oci_parse($c, "select b1 from lob_001_tab where id = 1");
46oci_execute($s);
47var_dump(oci_fetch_array($s, OCI_RETURN_LOBS));
48
49echo "Test 4 SQLT_BLOB (an alias for OCI_B_BLOB) bind\n";
50
51$statement = oci_parse($c, "insert into lob_001_tab (id, b1) values (2, empty_blob()) returning b1 into :v_b1 ");
52$blob = oci_new_descriptor($c,OCI_D_LOB);
53var_dump(oci_bind_by_name($statement, ":v_b1", $blob, -1, SQLT_BLOB));
54oci_execute($statement, OCI_DEFAULT);
55var_dump($blob->write("test row 2"));
56
57$s = oci_parse($c, "select b1 from lob_001_tab where id = 2");
58oci_execute($s);
59var_dump(oci_fetch_array($s, OCI_RETURN_LOBS));
60
61// Cleanup
62
63$stmtarray = array(
64    "drop table lob_001_tab"
65);
66
67oci8_test_sql_execute($c, $stmtarray);
68
69?>
70--EXPECTF--
71Test 1 OCI_B_BLOB bind
72bool(true)
73object(OCILob)#%d (1) {
74  ["descriptor"]=>
75  resource(%d) of type (oci8 descriptor)
76}
77Test 2
78int(4)
79int(4)
80bool(true)
81int(6)
82bool(false)
83Test 3
84array(2) {
85  [0]=>
86  string(20) "test%0%0%0%0%0%0%0%0%0%0string"
87  ["B1"]=>
88  string(20) "test%0%0%0%0%0%0%0%0%0%0string"
89}
90Test 4 SQLT_BLOB (an alias for OCI_B_BLOB) bind
91bool(true)
92int(10)
93array(2) {
94  [0]=>
95  string(10) "test row 2"
96  ["B1"]=>
97  string(10) "test row 2"
98}
99