Pergunta

My server is nginx and I use adodb5 to manage the connexion to the Oracle DB.

This db query returns rows in a SQL software like SQLDevelopper but I don't know how to make it work in my case.

$sql = "SELECT geom_object FROM geom_table";

Whereas this other request works :

$sql = "SELECT id FROM geom_table";

My connecting code is correct because all my queries return some data, except those involving SDO_GEOMETRY.

include ("adodb5/adodb-exceptions.inc.php"); 
include ("adodb5/adodb-errorhandler.inc.php"); 
include ("adodb5/adodb.inc.php");

try {   
    $db = NewADOConnection("oci8"); 
    $db->Connect($sid, $user, $password);
    $db->SetFetchMode(ADODB_FETCH_ASSOC);
} catch (exception $e) { 
    var_dump($e); 
    adodb_backtrace($e->gettrace());
    exit;
}

try 
{ 
    $ret = $db->GetArray($sql);
    print count($ret);
} 

catch (exception $e) 
{ 
    print $e->msg; 
    exit;
}
Foi útil?

Solução

The MDSYS.SDO_GEOMTRY field can not be hanlded as it is in PHP.

First I needed to modify my SQL request to return a Well Known Text :

$sql = "SELECT sdo_util.to_wktgeometry(geom_object) FROM geom_table";

Reading the Oracle Documentation on SDO_UTIL we can see that the TO_WKTGEOMETRY return a CLOB.

PHP can still not read the value of the data. There's one more important step, reading the CLOB. The Php documentation about OCI-Lob informs us that there are two functions able to read a CLOB and return a string : load and read.

$conn = oci_connect($user_prospect, $password_prospect, $sid_prospect);

if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$stid = oci_parse($conn, $sql);
oci_execute($stid);

while (($row = oci_fetch_array($stid)) != false) {
    echo $row[column_of_geometry_object]->load();
}

oci_free_statement($stid);
oci_close($conn);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top