P. 1
Underground Php Oracle Manual

Underground Php Oracle Manual

|Views: 816|Likes:
Published by SANGARE SOULEYMANE

More info:

Published by: SANGARE SOULEYMANE on Apr 25, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/12/2013

pdf

text

original

Sometimes you may need to create a PL/SQL function to decompose spatial data into simple types to
return them to PHP. This example uses the COLA_MARKETS table from example 1-8 of the Oracle Database
Express 2 Day Plus Locator Developer Guide:

http://download.oracle.com/docs/cd/B25329_01/doc/appdev.102/b28004/xe_locator.ht
m#CIHEBIDA

186

Using Oracle Locator for Spatial Mapping

Before continuing, execute the three statements given in the manual to create the table, insert the meta-data
into user_sdo_geom_metadata table, and create the index.
Next, insert a sample row. The row describes a polygon of (x,y) ordinates which are given as pairs in
the SDO_ORDINATE_ARRAY array:

Script 59: cm1.sql

insert into cola_markets values (
301, -- market ID number
'polygon',
sdo_geometry (
2003, -- two-dimensional polygon
null,
null,
sdo_elem_info_array(1,1003,1), -- one polygon (exterior polygon ring)
sdo_ordinate_array(5,1, 8,1, 8,6, 5,7, 5,1) -- list of X,Y coordinates

)

);

commit;

A decomposition function helps query the coordinates in PHP. Note the alias cm (an alias here is also
known as a correlation name) for the table in the query. This allows the sdo_ordinates collection to be
included as a select column:

Script 60: cm2.sql

create or replace procedure myproc(p_id in number, p_o out sdo_ordinate_array) as

begin

select cm.shape.sdo_ordinates
into p_o
from cola_markets cm
where mkt_id = p_id;

end;

/
show errors

The coordinates can now be retrieved in PHP as a collection:

Script 61: cm.php

$c = oci_connect('hr', 'hrpwd', 'localhost/XE');

$s = oci_parse($c, "begin myproc(:id, :ords); end;");
$id = 301;
oci_bind_by_name($s, ":id", $id);
$ords = oci_new_collection($c, "SDO_ORDINATE_ARRAY");
oci_bind_by_name($s, ":ords", $ords, -1, OCI_B_NTY);
oci_execute($s);

for ($i = 0; $i < $ords->size(); $i++) {

187

Using PL/SQL With OCI8

$v = $ords->getElem($i);
echo "Value: $v\n";

}

?>

The output is the list of coordinates that were inserted in the SDO_ORDINATE_ARRAY:
Value: 5
Value: 1
Value: 8
Value: 1
Value: 8
Value: 6
Value: 5
Value: 7
Value: 5
Value: 1

Similar techniques to these example given, or those techniques in the earlier section Using PL/SQL and SQL
Object Types in PHP can be used to fetch other Locator data, if required.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->