2

我想在 PHP 中获取一个 Oracle 10g 表到 JSON,以便在 GMap APIv3 中稀疏它。到目前为止,我可以获取 Oracle 表的第一行,但我不知道该怎么做。

到目前为止我使用这个:

$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"}

然后我不确定 JSON 输出是否会像这样在 GMap 中得到很好的结构,如果它完整的话。

4

1 回答 1

1

这很好用:

<?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));

?>
于 2012-12-13T13:57:35.833 回答