Search Google

Sunday, August 02, 2009

Use Google Spreadsheet as DB

每天都有新鮮事!
今天的新鮮事則是發現可以把Google spreadsheet拿來當作DB用~

下面兩個links有蠻詳盡的說明:
http://ouseful.wordpress.com/2009/05/14/querying-a-google-spreadsheet-of-mps-expenses-data-so-who-claimed-for-biscuits/
http://ouseful.wordpress.com/2009/05/18/using-google-spreadsheets-as-a-databace-with-the-google-visualisation-api-query-language/

我在試的時候發現如果想要用修改URL方式將spreadsheet拿來當作DB用,光是到spreadsheet的[Share]中設定Get the link to share...將view與edit權限開給所有人還不夠,還要publish spreadsheet,不然就會有access denied的錯誤訊息。

下面就貼個範例好了:
Publish之後的spreadsheet --> http://spreadsheets.google.com/pub?key=tsaL9uDLIVQLQup8e-67sjw
加上DB query --> http://spreadsheets.google.com/tq?tqx=out:html&tq=select%20A,B,C%20where%20A%20contains%20'PHP'%20order%20by%20A&key=tsaL9uDLIVQLQup8e-67sjw

PS. 不過這畢竟不是真的DB,所以有些statement要改一下,例如LIKE要改成CONTAINS,然後statement中的欄位名稱要用spreadsheet裡的ABCD,有點不太人性化,但是對於完全不想要自己架(或找DB)server的狀況下可以藉由spreadsheet來做到動態網頁。

No comments: