xref: /PHP-8.2/ext/oci8/tests/lob_019.phpt (revision b5a14e6c)
1--TEST--
2oci_lob_write()/erase()/read() with BLOBs
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." (blob)
18                      VALUES (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);
29
30$str = "this is a biiiig faaat test string. why are you reading it, I wonder? =)";
31var_dump($blob->write($str));
32var_dump($blob->erase(0, 10));
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
42var_dump($row[0]->read(5));
43var_dump($row[0]->read(5));
44var_dump($row[0]->read(5));
45
46require __DIR__.'/drop_table.inc';
47
48echo "Done\n";
49
50?>
51--EXPECTF--
52object(OCILob)#%d (1) {
53  ["descriptor"]=>
54  resource(%d) of type (oci8 descriptor)
55}
56int(72)
57int(10)
58array(2) {
59  [0]=>
60  object(OCILob)#%d (1) {
61    ["descriptor"]=>
62    resource(%d) of type (oci8 descriptor)
63  }
64  ["BLOB"]=>
65  object(OCILob)#%d (1) {
66    ["descriptor"]=>
67    resource(%d) of type (oci8 descriptor)
68  }
69}
70string(5) "%0%0%0%0%0"
71string(5) "%0%0%0%0%0"
72string(5) "biiii"
73Done
74