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