xref: /PHP-8.0/ext/oci8/tests/lob_003.phpt (revision 824a2bf1)
1--TEST--
2oci_lob_read() and friends
3--SKIPIF--
4<?php
5$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
6require(__DIR__.'/skipif.inc');
7?>
8--FILE--
9<?php
10
11require __DIR__.'/connect.inc';
12require __DIR__.'/create_table.inc';
13
14$ora_sql = "INSERT INTO
15                       ".$schema.$table_name." (blob)
16                      VALUES (empty_blob())
17                      RETURNING
18                               blob
19                      INTO :v_blob ";
20
21$statement = oci_parse($c,$ora_sql);
22$blob = oci_new_descriptor($c,OCI_D_LOB);
23oci_bind_by_name($statement,":v_blob", $blob,-1,OCI_B_BLOB);
24oci_execute($statement, OCI_DEFAULT);
25
26var_dump($blob);
27
28var_dump($blob->write("test"));
29var_dump($blob->tell());
30var_dump($blob->seek(10, OCI_SEEK_CUR));
31var_dump($blob->write("string"));
32var_dump($blob->flush());
33
34oci_commit($c);
35
36$select_sql = "SELECT blob FROM ".$schema.$table_name." FOR UPDATE";
37$s = oci_parse($c, $select_sql);
38oci_execute($s, OCI_DEFAULT);
39
40var_dump($row = oci_fetch_array($s));
41
42try {
43    var_dump($row[0]->read(-1));
44} catch (ValueError $e) {
45    echo $e->getMessage(), "\n";
46}
47var_dump($row[0]->read(10000));
48
49require __DIR__.'/drop_table.inc';
50
51echo "Done\n";
52
53?>
54--EXPECTF--
55object(OCILob)#%d (1) {
56  ["descriptor"]=>
57  resource(%d) of type (oci8 descriptor)
58}
59int(4)
60int(4)
61bool(true)
62int(6)
63bool(false)
64array(2) {
65  [0]=>
66  object(OCILob)#%d (1) {
67    ["descriptor"]=>
68    resource(%d) of type (oci8 descriptor)
69  }
70  ["BLOB"]=>
71  object(OCILob)#%d (1) {
72    ["descriptor"]=>
73    resource(%d) of type (oci8 descriptor)
74  }
75}
76OCILob::read(): Argument #1 ($length) must be greater than 0
77string(20) "test����������string"
78Done
79