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