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