1--TEST-- 2Basic XMLType test 3--EXTENSIONS-- 4simplexml 5oci8 6--SKIPIF-- 7<?php 8$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs 9require(__DIR__.'/skipif.inc'); 10?> 11--FILE-- 12<?php 13 14require(__DIR__."/connect.inc"); 15 16// Initialization 17 18$stmtarray = array( 19 "drop table xtt", 20 "create table xtt 21 (xt_id number, xt_spec xmltype) 22 xmltype xt_spec store as clob", 23 "insert into xtt (xt_id, xt_spec) values 24 (1, 25 xmltype('<?xml version=\"1.0\"?> 26 <Xt> 27 <XtId>1</XtId> 28 <Size>Big</Size> 29 <Area>12345</Area> 30 <Hardness>20</Hardness> 31 <Lip>Curved</Lip> 32 <Color>Red</Color> 33 <Nice>N</Nice> 34 <Compact>Tiny</Compact> 35 <Material>Steel</Material> 36 </Xt>'))" 37); 38 39oci8_test_sql_execute($c, str_replace("\r", "", $stmtarray)); 40 41function do_query($c) 42{ 43 $s = oci_parse($c, 'select XMLType.getClobVal(xt_spec) 44 from xtt where xt_id = 1'); 45 oci_execute($s); 46 $row = oci_fetch_row($s); 47 $data = $row[0]->load(); 48 var_dump($data); 49 return($data); 50} 51 52// Check 53echo "Initial Data\n"; 54$data = do_query($c); 55 56// Manipulate the data using SimpleXML 57$sx = simplexml_load_string($data); 58$sx->Hardness = $sx->Hardness - 1; 59$sx->Nice = 'Y'; 60 61// Insert changes using a temporary CLOB 62$s = oci_parse($c, 'update xtt 63 set xt_spec = XMLType(:clob) 64 where xt_id = 1'); 65$lob = oci_new_descriptor($c, OCI_D_LOB); 66oci_bind_by_name($s, ':clob', $lob, -1, OCI_B_CLOB); 67$lob->writeTemporary($sx->asXml()); 68oci_execute($s); 69$lob->close(); 70 71// Verify 72echo "Verify\n"; 73$data = do_query($c); 74 75// Cleanup 76 77$stmtarray = array( 78 "drop table xtt", 79); 80 81oci8_test_sql_execute($c, $stmtarray); 82 83echo "Done\n"; 84 85?> 86--EXPECT-- 87Initial Data 88string(316) "<?xml version="1.0"?> 89 <Xt> 90 <XtId>1</XtId> 91 <Size>Big</Size> 92 <Area>12345</Area> 93 <Hardness>20</Hardness> 94 <Lip>Curved</Lip> 95 <Color>Red</Color> 96 <Nice>N</Nice> 97 <Compact>Tiny</Compact> 98 <Material>Steel</Material> 99 </Xt>" 100Verify 101string(309) "<?xml version="1.0"?> 102<Xt> 103 <XtId>1</XtId> 104 <Size>Big</Size> 105 <Area>12345</Area> 106 <Hardness>19</Hardness> 107 <Lip>Curved</Lip> 108 <Color>Red</Color> 109 <Nice>Y</Nice> 110 <Compact>Tiny</Compact> 111 <Material>Steel</Material> 112 </Xt> 113" 114Done 115