lob_029.phpt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. --TEST--
  2. reading/writing BFILE LOBs
  3. --EXTENSIONS--
  4. oci8
  5. --SKIPIF--
  6. <?php
  7. $target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
  8. require(__DIR__.'/skipif.inc');
  9. ob_start();
  10. phpinfo(INFO_MODULES);
  11. $phpinfo = ob_get_clean();
  12. if (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. }
  16. if (substr(PHP_OS, 0, 3) == 'WIN') die("skip Test script not ported to Windows");
  17. ?>
  18. --FILE--
  19. <?php
  20. require(__DIR__.'/connect.inc');
  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. // Setup
  29. $s = oci_parse($c, "drop table FileTest");
  30. @oci_execute($s);
  31. $s = oci_parse($c, "drop directory TestDir");
  32. @oci_execute($s);
  33. $s = oci_parse($c, "create directory TestDir as '$realdirname'");
  34. oci_execute($s);
  35. file_put_contents($fullname1, 'Some text in the bfile 1');
  36. file_put_contents($fullname2, 'Some text in the bfile 2');
  37. file_put_contents($fullname3, 'Some text in the bfile 3');
  38. $s = oci_parse($c, "create table FileTest (FileNum number, FileDesc varchar2(30), Image bfile)");
  39. oci_execute($s);
  40. $s = oci_parse($c, "insert into FileTest (FileNum, FileDesc, Image) values (1, 'Description 1', bfilename('TESTDIR', '$realfilename1'))");
  41. oci_execute($s);
  42. $s = oci_parse($c, "insert into FileTest (FileNum, FileDesc, Image) values (2, 'Description 2', bfilename('TESTDIR', '$realfilename2'))");
  43. oci_execute($s);
  44. $s = oci_parse($c, "insert into FileTest (FileNum, FileDesc, Image) values (3, 'Description 3', bfilename('TESTDIR', '$realfilename3'))");
  45. oci_execute($s);
  46. // Run tests
  47. echo "Test 1. Check how many rows in the table\n";
  48. $s = oci_parse($c, "select count(*) numrows from FileTest");
  49. oci_execute($s);
  50. oci_fetch_all($s, $res);
  51. var_dump($res);
  52. echo "Test 2\n";
  53. $s = oci_parse($c, "select * from FileTest order by FileNum");
  54. oci_execute($s);
  55. oci_fetch_all($s, $res);
  56. var_dump($res);
  57. echo "Test 3\n";
  58. $d = oci_new_descriptor($c, OCI_D_FILE);
  59. $s = oci_parse($c, "insert into FileTest (FileNum, FileDesc, Image) values (2, 'Description 2', bfilename('TESTDIR', '$realfilename1')) returning Image into :im");
  60. oci_bind_by_name($s, ":im", $d, -1, OCI_B_BFILE);
  61. oci_execute($s);
  62. $r = $d->read(40);
  63. var_dump($r);
  64. unlink($fullname1);
  65. unlink($fullname2);
  66. unlink($fullname3);
  67. $s = oci_parse($c, "drop table FileTest");
  68. oci_execute($s);
  69. $s = oci_parse($c, "drop directory TestDir");
  70. oci_execute($s);
  71. echo "Done\n";
  72. ?>
  73. --EXPECT--
  74. Test 1. Check how many rows in the table
  75. array(1) {
  76. ["NUMROWS"]=>
  77. array(1) {
  78. [0]=>
  79. string(1) "3"
  80. }
  81. }
  82. Test 2
  83. array(3) {
  84. ["FILENUM"]=>
  85. array(3) {
  86. [0]=>
  87. string(1) "1"
  88. [1]=>
  89. string(1) "2"
  90. [2]=>
  91. string(1) "3"
  92. }
  93. ["FILEDESC"]=>
  94. array(3) {
  95. [0]=>
  96. string(13) "Description 1"
  97. [1]=>
  98. string(13) "Description 2"
  99. [2]=>
  100. string(13) "Description 3"
  101. }
  102. ["IMAGE"]=>
  103. array(3) {
  104. [0]=>
  105. string(24) "Some text in the bfile 1"
  106. [1]=>
  107. string(24) "Some text in the bfile 2"
  108. [2]=>
  109. string(24) "Some text in the bfile 3"
  110. }
  111. }
  112. Test 3
  113. string(24) "Some text in the bfile 1"
  114. Done