define3.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. --TEST--
  2. Test oci_define_by_name() LOB descriptor
  3. --SKIPIF--
  4. <?php
  5. $target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
  6. require(dirname(__FILE__).'/skipif.inc');
  7. ?>
  8. --FILE--
  9. <?php
  10. require(dirname(__FILE__)."/connect.inc");
  11. $stmtarray = array(
  12. "drop table phpdefblobtable",
  13. "create table phpdefblobtable (id number(10), fileimage blob)"
  14. );
  15. oci8_test_sql_execute($c, $stmtarray);
  16. // Load data
  17. $stmt = oci_parse ($c, "insert into phpdefblobtable (id, fileimage) values (:id, empty_blob()) returning fileimage into :fileimage");
  18. $fileimage = oci_new_descriptor($c,OCI_D_LOB);
  19. oci_bind_by_name($stmt,":id",$id);
  20. oci_bind_by_name($stmt,":fileimage",$fileimage,-1,OCI_B_BLOB);
  21. $id = 1;
  22. oci_execute($stmt, OCI_DEFAULT);
  23. $fileimage->savefile(dirname(__FILE__)."/test.gif");
  24. $data = $fileimage->load();
  25. var_dump(md5($data)); // original md5
  26. oci_commit($c);
  27. // New row with different data
  28. $id = 2;
  29. $data = strrev($data);
  30. var_dump(md5($data));
  31. oci_execute($stmt, OCI_DEFAULT);
  32. $fileimage->save($data);
  33. oci_commit($c);
  34. echo "Test 1\n";
  35. $stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
  36. var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $f));
  37. oci_execute($stmt);
  38. while (oci_fetch($stmt)) {
  39. var_dump($f);
  40. echo "file md5:" . md5($f->load()) . "\n";
  41. }
  42. echo "Test 2\n";
  43. $stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
  44. var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $outdata, SQLT_STR));
  45. oci_execute($stmt);
  46. while (oci_fetch($stmt)) {
  47. echo "file md5:" . md5($outdata) . "\n";
  48. }
  49. echo "Test 3\n";
  50. $stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
  51. var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $outdata, SQLT_BIN));
  52. oci_execute($stmt);
  53. while (oci_fetch($stmt)) {
  54. echo "file md5:" . md5($outdata) . "\n";
  55. }
  56. echo "Test 4\n";
  57. $fid = oci_new_descriptor($c,OCI_D_LOB);
  58. $stmt = oci_parse($c, "SELECT fileimage FROM phpdefblobtable");
  59. var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fid));
  60. oci_execute($stmt);
  61. while (oci_fetch($stmt)) {
  62. echo "file md5:" . md5($fid->load()) . "\n";
  63. }
  64. $stmtarray = array(
  65. "drop table phpdefblobtable"
  66. );
  67. oci8_test_sql_execute($c, $stmtarray);
  68. echo "Done\n";
  69. ?>
  70. --EXPECTF--
  71. string(32) "614fcbba1effb7caa27ef0ef25c27fcf"
  72. string(32) "06d4f219d946c74d748d43932cd9dcb2"
  73. Test 1
  74. bool(true)
  75. object(OCI-Lob)#%d (1) {
  76. ["descriptor"]=>
  77. resource(%d) of type (oci8 descriptor)
  78. }
  79. file md5:614fcbba1effb7caa27ef0ef25c27fcf
  80. object(OCI-Lob)#%d (1) {
  81. ["descriptor"]=>
  82. resource(%d) of type (oci8 descriptor)
  83. }
  84. file md5:06d4f219d946c74d748d43932cd9dcb2
  85. Test 2
  86. bool(true)
  87. Warning: oci_fetch(): ORA-00932: %s on line %d
  88. Test 3
  89. bool(true)
  90. file md5:614fcbba1effb7caa27ef0ef25c27fcf
  91. file md5:06d4f219d946c74d748d43932cd9dcb2
  92. Test 4
  93. bool(true)
  94. file md5:614fcbba1effb7caa27ef0ef25c27fcf
  95. file md5:06d4f219d946c74d748d43932cd9dcb2
  96. Done