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