2012-04-10 42 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);