In this old forum I put information about creating a TinyWebDB using PHP: https://groups.google.com/forum/#!category-topic/mitappinventortest/apps-tips--tricks/wi8w1x6ljPc
Now I will post the code more clearly and add an extension to encrypt the data.
1.- Create a TinyWebDB database with a PHP file.
We upload this file to our hosting:
tinywebdb.php
<?php
// Juan Antonio Villalpando
// http://kio4.com/appinventor/8A_MiniWebDB_TinyWebDB.htm
$receive_post = $_SERVER["REQUEST_URI"];
$tag = $_POST['tag'];
$file = 'tinywebdb.htm';
// If file not exist, create.
if (!file_exists($file)) {$create = fopen($file, 'w');}
if(strpos($receive_post,'storeavalue')){
//////////////////////////////// If exist that tag, DELETE it
//// to avoid repeating that tag.
$arc = file($file);
$auxi = fopen($file,"w");
foreach($arc as $line)
{ $fields = explode(":", $line);
if ($fields[0] != $tag) { fputs($auxi, $line); }
}
fclose($auxi);
/////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
// STORE TAG AND VALUE
$valueToStore = $_POST['value'];
$line = $tag.":".$valueToStore.":\n";
$auxi = fopen($file, 'a'); // Add $line to file tinywebdb.htm
fwrite($auxi, $line);
} else {
///////////////////////////////////////////////////////////////////////////////////////////////////
// GET VALUE OF TAG.
// Search in file tinywebdb.htm value for that tag.
$auxi = fopen($file, 'r');
$exist = "";
while(!feof($auxi)){
$line = fgets($auxi);
$fields = explode(":", $line);
if ($fields[0] == $tag) {
$value =$fields[1];
$exist = true;
}
}
// Sends result.
if ($exist){ $result = array("VALUE", $tag, $value);} // Send value
else { $result = array("VALUE", $tag, "Not_found");} // Send "Not_found".
$result_in_JSON = json_encode($result);
echo $result_in_JSON;
}
fclose($auxi);
?>
-
We place a TinyWebDB component and in Property ServiceURL we put the internet address of the tinywebdb.php file, example: https://mydomain/tinywebdb.php
-
We can use the TinyWebDB component as we normally do.
-
The data will be saved in the tinywebdb.htm file