xref: /PHP-8.1/ext/oci8/tests/lob_011.phpt (revision b5a14e6c)
1--TEST--
2oci_lob_copy()
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';
14require __DIR__.'/create_table.inc';
15
16$ora_sql = "INSERT INTO
17                       ".$schema.$table_name." (id, blob)
18                      VALUES (1, empty_blob())
19                      RETURNING
20                               blob
21                      INTO :v_blob ";
22
23$statement = oci_parse($c,$ora_sql);
24$blob = oci_new_descriptor($c,OCI_D_LOB);
25oci_bind_by_name($statement,":v_blob", $blob,-1,OCI_B_BLOB);
26oci_execute($statement, OCI_DEFAULT);
27
28var_dump($blob->write("some string here. string, I said"));
29oci_commit($c);
30
31$ora_sql = "INSERT INTO
32                       ".$schema.$table_name." (id, blob)
33                      VALUES (2, empty_blob())
34                      RETURNING
35                               blob
36                      INTO :v_blob ";
37
38$statement = oci_parse($c,$ora_sql);
39$blob = oci_new_descriptor($c,OCI_D_LOB);
40oci_bind_by_name($statement,":v_blob", $blob,-1,OCI_B_BLOB);
41oci_execute($statement, OCI_DEFAULT);
42
43oci_commit($c);
44
45$select_sql = "SELECT blob FROM ".$schema.$table_name." WHERE id = 1";
46$s = oci_parse($c, $select_sql);
47oci_execute($s);
48
49$row1 = oci_fetch_array($s);
50
51$select_sql = "SELECT blob FROM ".$schema.$table_name." WHERE id = 2 FOR UPDATE";
52$s = oci_parse($c, $select_sql);
53oci_execute($s, OCI_DEFAULT);
54
55$row2 = oci_fetch_array($s);
56
57var_dump(oci_lob_copy($row2[0], $row1[0]));
58var_dump($row1[0]->read(100));
59
60oci_commit($c);
61
62$select_sql = "SELECT blob FROM ".$schema.$table_name." WHERE id = 2 FOR UPDATE";
63$s = oci_parse($c, $select_sql);
64oci_execute($s, OCI_DEFAULT);
65
66var_dump($row2 = oci_fetch_array($s, OCI_RETURN_LOBS));
67
68require __DIR__.'/drop_table.inc';
69
70echo "Done\n";
71
72?>
73--EXPECT--
74int(32)
75bool(true)
76string(32) "some string here. string, I said"
77array(2) {
78  [0]=>
79  string(32) "some string here. string, I said"
80  ["BLOB"]=>
81  string(32) "some string here. string, I said"
82}
83Done
84