xref: /PHP-8.3/ext/oci8/tests/define3.phpt (revision a53e5617)
1--TEST--
2Test oci_define_by_name() LOB descriptor
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$stmtarray = array(
17    "drop table phpdefblobtable",
18    "create table phpdefblobtable (id number(10), fileimage blob)"
19);
20
21oci8_test_sql_execute($c, $stmtarray);
22
23// Load data
24$stmt = oci_parse ($c, "insert into phpdefblobtable (id, fileimage) values (:id, empty_blob()) returning fileimage into :fileimage");
25$fileimage = oci_new_descriptor($c,OCI_D_LOB);
26oci_bind_by_name($stmt,":id",$id);
27oci_bind_by_name($stmt,":fileimage",$fileimage,-1,OCI_B_BLOB);
28$id = 1;
29oci_execute($stmt, OCI_DEFAULT);
30$fileimage->saveFile(__DIR__."/test.gif");
31$data = $fileimage->load();
32var_dump(md5($data));  // original md5
33oci_commit($c);
34
35// New row with different data
36$id = 2;
37$data = strrev($data);
38var_dump(md5($data));
39oci_execute($stmt, OCI_DEFAULT);
40$fileimage->save($data);
41oci_commit($c);
42
43echo "Test 1\n";
44$stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
45var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $f));
46oci_execute($stmt);
47
48while (oci_fetch($stmt)) {
49   var_dump($f);
50   echo "file md5:" . md5($f->load()) . "\n";
51}
52
53echo "Test 2\n";
54$stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
55var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $outdata, SQLT_STR));
56oci_execute($stmt);
57
58while (oci_fetch($stmt)) {
59   echo "file md5:" . md5($outdata) . "\n";
60}
61
62echo "Test 3\n";
63$stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
64var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $outdata, SQLT_BIN));
65oci_execute($stmt);
66
67while (oci_fetch($stmt)) {
68   echo "file md5:" . md5($outdata) . "\n";
69}
70
71echo "Test 4\n";
72$fid = oci_new_descriptor($c,OCI_D_LOB);
73$stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
74var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fid));
75oci_execute($stmt);
76
77while (oci_fetch($stmt)) {
78   echo "file md5:" . md5($fid->load()) . "\n";
79}
80
81$stmtarray = array(
82    "drop table phpdefblobtable"
83);
84
85oci8_test_sql_execute($c, $stmtarray);
86
87echo "Done\n";
88
89?>
90--EXPECTF--
91string(32) "614fcbba1effb7caa27ef0ef25c27fcf"
92string(32) "06d4f219d946c74d748d43932cd9dcb2"
93Test 1
94bool(true)
95object(OCILob)#%d (1) {
96  ["descriptor"]=>
97  resource(%d) of type (oci8 descriptor)
98}
99file md5:614fcbba1effb7caa27ef0ef25c27fcf
100object(OCILob)#%d (1) {
101  ["descriptor"]=>
102  resource(%d) of type (oci8 descriptor)
103}
104file md5:06d4f219d946c74d748d43932cd9dcb2
105Test 2
106bool(true)
107
108Warning: oci_fetch(): ORA-00932: %s on line %d
109Test 3
110bool(true)
111file md5:614fcbba1effb7caa27ef0ef25c27fcf
112file md5:06d4f219d946c74d748d43932cd9dcb2
113Test 4
114bool(true)
115file md5:614fcbba1effb7caa27ef0ef25c27fcf
116file md5:06d4f219d946c74d748d43932cd9dcb2
117Done
118