define3.phpt 2.8 KB

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