xref: /PHP-8.2/ext/oci8/tests/lob_029.phpt (revision b5a14e6c)
1--TEST--
2reading/writing BFILE LOBs
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
8require(__DIR__.'/skipif.inc');
9ob_start();
10phpinfo(INFO_MODULES);
11$phpinfo = ob_get_clean();
12if (preg_match('/Compile-time ORACLE_HOME/', $phpinfo) !== 1) {
13    // Assume building PHP with an ORACLE_HOME means the tested DB is on the same machine as PHP
14    die("skip this test won't work with remote Oracle");
15}
16if (substr(PHP_OS, 0, 3) == 'WIN') die("skip Test script not ported to Windows");
17?>
18--FILE--
19<?php
20
21require(__DIR__.'/connect.inc');
22
23$realdirname = "/tmp";  // Use /tmp because a local dir can give ORA-22288 depending on perms
24$realfilename1 = "oci8bfiletest1.txt";
25$fullname1 = $realdirname."/".$realfilename1;
26$realfilename2 = "oci8bfiletest2.txt";
27$fullname2 = $realdirname."/".$realfilename2;
28$realfilename3 = "oci8bfiletest3.txt";
29$fullname3 = $realdirname."/".$realfilename3;
30
31// Setup
32$s = oci_parse($c, "drop table FileTest");
33@oci_execute($s);
34
35$s = oci_parse($c, "drop directory TestDir");
36@oci_execute($s);
37
38$s = oci_parse($c, "create directory TestDir as '$realdirname'");
39oci_execute($s);
40
41file_put_contents($fullname1, 'Some text in the bfile 1');
42file_put_contents($fullname2, 'Some text in the bfile 2');
43file_put_contents($fullname3, 'Some text in the bfile 3');
44
45$s = oci_parse($c, "create table FileTest (FileNum number, FileDesc varchar2(30), Image bfile)");
46oci_execute($s);
47
48$s = oci_parse($c, "insert into FileTest (FileNum, FileDesc, Image) values (1, 'Description 1', bfilename('TESTDIR', '$realfilename1'))");
49oci_execute($s);
50
51$s = oci_parse($c, "insert into FileTest (FileNum, FileDesc, Image) values (2, 'Description 2', bfilename('TESTDIR', '$realfilename2'))");
52oci_execute($s);
53
54$s = oci_parse($c, "insert into FileTest (FileNum, FileDesc, Image) values (3, 'Description 3', bfilename('TESTDIR', '$realfilename3'))");
55oci_execute($s);
56
57// Run tests
58
59echo "Test 1. Check how many rows in the table\n";
60
61$s = oci_parse($c, "select count(*) numrows from FileTest");
62oci_execute($s);
63oci_fetch_all($s, $res);
64var_dump($res);
65
66echo "Test 2\n";
67$s = oci_parse($c, "select * from FileTest order by FileNum");
68oci_execute($s);
69oci_fetch_all($s, $res);
70var_dump($res);
71
72echo "Test 3\n";
73$d = oci_new_descriptor($c, OCI_D_FILE);
74
75$s = oci_parse($c, "insert into FileTest (FileNum, FileDesc, Image) values (2, 'Description 2', bfilename('TESTDIR', '$realfilename1')) returning Image into :im");
76oci_bind_by_name($s, ":im", $d, -1, OCI_B_BFILE);
77oci_execute($s);
78
79$r = $d->read(40);
80var_dump($r);
81
82unlink($fullname1);
83unlink($fullname2);
84unlink($fullname3);
85
86$s = oci_parse($c, "drop table FileTest");
87oci_execute($s);
88
89$s = oci_parse($c, "drop directory TestDir");
90oci_execute($s);
91
92echo "Done\n";
93?>
94--EXPECT--
95Test 1. Check how many rows in the table
96array(1) {
97  ["NUMROWS"]=>
98  array(1) {
99    [0]=>
100    string(1) "3"
101  }
102}
103Test 2
104array(3) {
105  ["FILENUM"]=>
106  array(3) {
107    [0]=>
108    string(1) "1"
109    [1]=>
110    string(1) "2"
111    [2]=>
112    string(1) "3"
113  }
114  ["FILEDESC"]=>
115  array(3) {
116    [0]=>
117    string(13) "Description 1"
118    [1]=>
119    string(13) "Description 2"
120    [2]=>
121    string(13) "Description 3"
122  }
123  ["IMAGE"]=>
124  array(3) {
125    [0]=>
126    string(24) "Some text in the bfile 1"
127    [1]=>
128    string(24) "Some text in the bfile 2"
129    [2]=>
130    string(24) "Some text in the bfile 3"
131  }
132}
133Test 3
134string(24) "Some text in the bfile 1"
135Done
136