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