2012-04-10 61 views
1

我的情况如下: 我有一个MySQL数据库,我导出并插入到Fusion Table中。现在我需要修改php页面来查询Fusion Table而不是localhost db的数据。从PHP查询Fusion-Table

我已阅读关于从开发人员指南中查询Fusion-Tables的内容,但它指的是GData Java库和SQL API。在另一个网站上,我看到有其他库可用于查询,包括PHP所依赖的Zend框架,这与我的情况相关。然而,我还没有偶然发现任何示例或教程,它只是简单地展示了一个php页面,介绍如何查询简单的单元格,行或列,以及从哪里修改和改进编码以将其应用于设计。

我的问题是:

  1. 我是否需要安装/上传的托管空间中的一些库?

  2. 是否有一个php示例&查询Fusion Table数据的教程,我可能错过了?

  3. 任何人都可以提供给我一个线索如何查询例如行ID为5的纬度信息? (页所使用的路径检索:articles.php郎= EN & PG = comm_en &米=视图& commID = 88

下面是编码我在comm_en.php页,它从PHP查询到SQL数据。

预先感谢您!

Drini

<?php 
session_start(); 
foreach ($_REQUEST as $key => $value){ 
    $$key=addslashes(htmlspecialchars(strip_tags($value))); 
} 
if(isset($_GET["m"]))  {$m=$_GET["m"];}   else  {$m="";} 
if(isset($_GET["commID"]))  {$commID=$_GET["commID"];} else {$commID=1;} 
if(isset($_GET["lang"]))  {$lang=$_GET["lang"];} 
else {$lang="en";} 

Shfaq($m,$commID); 

function Shfaq($metod,$commID) 
{ 
switch($metod) 
{ 
case "view": 
     {View($commID);}   
    break; 
case "default": 
     {View($artID);}  
    break; 

} 
} // end of Shfaq(); 


function View($commID) 
{ 
    $link =mysql_connect("localhost", "db-user", "db-pass") or die ("E pamundur lidhja!"); 
mysql_select_db("DataBase-name") or die (mysql_error()); 
$queryComm = "SELECT * FROM communities WHERE id ='$commID' LIMIT 0,1"; 
$commRes=mysql_query($queryComm) or die(mysql_error()); 
$comm=mysql_fetch_array($commRes); 
$healthPerc = round(($comm["healthBooklet"]/$comm["totalChildNo"]), 3)*100 ; 

echo '  <table class="gpsbox" align="right"> 
     <caption>GPS Location</caption>     
     <tr><td>Latitude </td><td>'.$comm["latitude"].'</td></tr> 
     <tr><td>Longitude</td><td>'.$comm["longitude"].'</td></tr> 
    </table>....<html coding continues> 

回答

0
  1. 有一个PHP client library,你可以使用它,如果你希望(它可能访问从PHP Fusion Tables的最简单的方法)

  2. 下一页客户端库也有PHP sample code,只是来看看,它可能有助于你了解这个概念。

  3. 当你使用这个库,你可以简单地写SQL语句,即像

    select latitude from 123456 where id = 5; 
    

123456指你融合表的表ID。如果你的表是公开的,你甚至不必关心认证,但如果你想访问私人表或更新/插入数据,我建议使用OAuth for authentication。一般

示例代码可以在Google Fusion Tables API Sample Code

3

发现这里是如何与Fusion Tables的使用newest PHP API client library

use Google_Service_Fusiontables; 

$client_email = '<id>@developer.gserviceaccount.com'; 
$private_key = file_get_contents('<private key>.p12'); 
$scopes= array(
     'https://www.googleapis.com/auth/fusiontables', 
     'https://www.googleapis.com/auth/fusiontables.readonly', 
     ); 
$credentials = new Google_Auth_AssertionCredentials(
    $client_email, 
    $scopes, 
    $private_key 
); 

$client = new Google_Client(); 
$client->setAssertionCredentials($credentials); 
if ($client->getAuth()->isAccessTokenExpired()) { 
    $client->getAuth()->refreshTokenWithAssertion(); 
} 

$service = new Google_Service_Fusiontables($client); 
$result = $service->query->sql('SELECT <column> FROM <table id>'); 
var_dump($result);