2

I would like to fetch an Oracle 10g table to JSON in PHP in order to sparse it in GMap APIv3. So far I can fetch the first line of the Oracle table but I dont know how to do it for all.

I use this so far:

$conn = oci_connect($user, $pass, $host);

$sql  = oci_parse($conn, "select * from POINTS_CS_FRANCO WHERE CODE_CS = '711'");

oci_execute($sql);

class User {
    public $Code_CES = "";
    public $Nbr_Electeur = "";
    public $lat = "";
    public $lng = "";
}

while ($row = oci_fetch_assoc($sql)){
    $user = new User();
    $user->Code_CES = $row['CODE_CES'];
    $user->Nbr_Electeur = $row['NBR_ELECTEUR'];
    $user->lat = $row['LATITUDE'];
    $user->lng = $row['LONGITUDE'];
} 

echo json_encode($user);

?> 

// Returns: {"Code_CES":"CES 000","Nbr_Electeur":"8","lat":"48.834997","lng":"-67.530141"}

Then im not sure if the JSON output would be well-strutured like this to sparse in GMap if it would be complete.

  • ok I see. This much simpler than I thought. I use this solution and it works: http://stackoverflow.com/a/383664/1865154 –  Dec 12 '12 at 20:19
  • You can add the answer to your own question in that case. – Lenin Dec 13 '12 at 06:47

1 Answers1

1

This works good:

<?php

$conn = oci_connect($user, $pass, $host);

$sql  = oci_parse($conn, "select * from POINTS_CS_FRANCO WHERE CODE_CS = '711'");

oci_execute($sql);

$rows = array();
while($r = oci_fetch_assoc($sql)) {
    $rows[] = $r;
}

$locations =(json_encode($rows));

?>