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