php - using Google Docs as a database? -


i create simple php page site, show timetable / calendar data, each slot either free or have appointment in it.

because data 1 table, {month, day, hour, talk_name, talk_description}, thought why not use google docs spreadsheet database. ok, main reason i'm reading books how use mysql in php, i'm definately not on level to:

  • create nice admin interface managing events
  • make whole thing safe (i mean idea safety use .htaccess admin folder , make site read-only elsewhere).

on other hand use google spreadsheets editing table, way both security aspects , ui aspects solved.

my question how recommend me that? google docs can both publish in xml , csv formats. can use fgetcsv datas? can give me simple examples how parse csv, , if efficient (ok, less 50 views day), if (sorry abstract syntax)?

$source_csv = fgetcsv(...);  get_talk_name(x,y,z) {   rows in $source_csv {     if (month == x && day == y && hour == z) return talk_name   } }  get_talk_desc(x,y,z) {   rows in $source_csv {     if (month == x && day == y && hour == z) return talk_name   } } 

so, while might not wise or scalable, yes, can it. try code:

<?php $url = "https://spreadsheets.google.com/pub?hl=en&hl=en&key=0aupgxsru8e9udc1dy0touujlv0m0thm4cgjtsknsunc&output=csv"; $row=0;  if (($handle = fopen($url, "r")) !== false) {     while (($data = fgetcsv($handle, 1000, ",")) !== false) {         $num = count($data);         echo "<p> $num fields in line $row: <br /></p>\n";         $row++;         ($c=0; $c < $num; $c++) {             echo $data[$c] . "<br />\n";         }     }     fclose($handle); } 

basically, publish spreadsheet public, change output csv (from default html) manually editing url (ie, output=csv), fetch it, , iterate on line line using fgetcsv.

if spreadsheet looks this:

enter image description here

this output following csv in question:

array(2) {   [0]=>   string(4) "name"   [1]=>   string(5) "value" } array(2) {   [0]=>   string(3) "foo"   [1]=>   string(5) "13123" } array(2) {   [0]=>   string(3) "bar"   [1]=>   string(3) "331" } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -