1--TEST-- 2Basic XMLType test #2 3--SKIPIF-- 4<?php 5$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs 6require(__DIR__.'/skipif.inc'); 7if (!extension_loaded("simplexml")) die ("skip no simplexml extension"); 8?> 9--FILE-- 10<?php 11 12require(__DIR__.'/connect.inc'); 13 14// Initialization 15 16$stmtarray = array( 17 "drop table xmltype_02_tab", 18 "create table xmltype_02_tab (warehouse_id number, warehouse_spec xmltype)", 19); 20 21oci8_test_sql_execute($c, $stmtarray); 22 23// Run Test 24 25 26$id = 1; 27 28// Delete any current entry 29$s = oci_parse($c, "delete from xmltype_02_tab where warehouse_id = :id"); 30oci_bind_by_name($s, ':id', $id); 31oci_execute($s); 32 33// XML data to be inserted 34$xml =<<<EOF 35<?xml version="1.0"?> 36<Warehouse> 37<WarehouseId>1</WarehouseId> 38<WarehouseName>Southlake, Texas</WarehouseName> 39<Building>Owned</Building> 40<Area>25000</Area> 41<Docks>2</Docks> 42<DockType>Rear load</DockType> 43<WaterAccess>true</WaterAccess> 44<RailAccess>N</RailAccess> 45<Parking>Street</Parking> 46<VClearance>10</VClearance> 47</Warehouse> 48EOF; 49 50echo "Test 1 Insert new XML data using a temporary CLOB\n"; 51$s = oci_parse($c, 52 "insert into xmltype_02_tab (warehouse_id, warehouse_spec) 53 values (:id, XMLType(:clob))"); 54oci_bind_by_name($s, ':id', $id); 55$lob = oci_new_descriptor($c, OCI_D_LOB); 56oci_bind_by_name($s, ':clob', $lob, -1, OCI_B_CLOB); 57$lob->writeTemporary($xml); 58oci_execute($s); 59$lob->close(); 60 61// Query the row back 62$s = oci_parse($c, 'select xmltype.getclobval(warehouse_spec) 63 from xmltype_02_tab where warehouse_id = :id'); 64$r = oci_bind_by_name($s, ':id', $id); 65oci_execute($s); 66$row = oci_fetch_array($s, OCI_NUM); 67 68var_dump($row); 69 70echo "Test 2 Manipulate the data using SimpleXML\n"; 71 72$sx = simplexml_load_string($row[0]->load()); 73$row[0]->free(); 74var_dump($sx); 75 76$sx->Docks -= 1; // change the data 77 78var_dump($sx); 79 80echo "Test 3: Update changes using a temporary CLOB\n"; 81 82$s = oci_parse($c, 'update xmltype_02_tab 83 set warehouse_spec = XMLType(:clob) 84 where warehouse_id = :id'); 85oci_bind_by_name($s, ':id', $id); 86$lob = oci_new_descriptor($c, OCI_D_LOB); 87oci_bind_by_name($s, ':clob', $lob, -1, OCI_B_CLOB); 88$lob->writeTemporary($sx->asXml()); 89oci_execute($s); 90$lob->close(); 91 92// Query the changed row back and print it 93$s = oci_parse($c, 'select xmltype.getclobval(warehouse_spec) 94 from xmltype_02_tab where warehouse_id = :id'); 95$r = oci_bind_by_name($s, ':id', $id); 96oci_execute($s); 97$row = oci_fetch_array($s, OCI_NUM); 98var_dump($row[0]->load()); 99$row[0]->free(); 100 101// Clean up 102 103$stmtarray = array( 104 "drop table xmltype_02_tab" 105); 106 107oci8_test_sql_execute($c, $stmtarray); 108 109?> 110--EXPECTF-- 111Test 1 Insert new XML data using a temporary CLOB 112array(1) { 113 [0]=> 114 object(OCILob)#%d (1) { 115 ["descriptor"]=> 116 resource(%d) of type (oci8 descriptor) 117 } 118} 119Test 2 Manipulate the data using SimpleXML 120object(SimpleXMLElement)#%d (10) { 121 ["WarehouseId"]=> 122 string(1) "1" 123 ["WarehouseName"]=> 124 string(16) "Southlake, Texas" 125 ["Building"]=> 126 string(5) "Owned" 127 ["Area"]=> 128 string(5) "25000" 129 ["Docks"]=> 130 string(1) "2" 131 ["DockType"]=> 132 string(9) "Rear load" 133 ["WaterAccess"]=> 134 string(4) "true" 135 ["RailAccess"]=> 136 string(1) "N" 137 ["Parking"]=> 138 string(6) "Street" 139 ["VClearance"]=> 140 string(2) "10" 141} 142object(SimpleXMLElement)#%d (10) { 143 ["WarehouseId"]=> 144 string(1) "1" 145 ["WarehouseName"]=> 146 string(16) "Southlake, Texas" 147 ["Building"]=> 148 string(5) "Owned" 149 ["Area"]=> 150 string(5) "25000" 151 ["Docks"]=> 152 string(1) "1" 153 ["DockType"]=> 154 string(9) "Rear load" 155 ["WaterAccess"]=> 156 string(4) "true" 157 ["RailAccess"]=> 158 string(1) "N" 159 ["Parking"]=> 160 string(6) "Street" 161 ["VClearance"]=> 162 string(2) "10" 163} 164Test 3: Update changes using a temporary CLOB 165string(%d) "<?xml version="1.0"?> 166<Warehouse> 167%sWarehouseId>1</WarehouseId> 168%sWarehouseName>Southlake, Texas</WarehouseName> 169%sBuilding>Owned</Building> 170%sArea>25000</Area> 171%sDocks>1</Docks> 172%sDockType>Rear load</DockType> 173%sWaterAccess>true</WaterAccess> 174%sRailAccess>N</RailAccess> 175%sParking>Street</Parking> 176%sVClearance>10</VClearance> 177</Warehouse> 178" 179