Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By Mmiscool
#46433 Putting values in to a database using esp basic.

I think I like this better than using thing speak as you can control and manage your own information. Its always better to use your own equipment and code rather than outsource it to a company that may or may not be around for ever.
User avatar
By cwilt
#46469
forlotto wrote:What they are would be possibly file lists and such...


For instance java I believe has its own database system... And you can use xml to store data to I would assume also I wonder if somehow we could use csv files or other files...


Thats why I wanted JSON. Ability read and write JSON files provides basic database system.
User avatar
By TheWaldorfer
#46790
Mmiscool wrote:I think I like this better than using thing speak as you can control and manage your own information. Its always better to use your own equipment and code rather than outsource it to a company that may or may not be around for ever.


Yep. Just get a cheap hosted server for 5 bucks a month with php & MySQL. Enryption would be fine but that is beyond the ESP's possibilities, isn't it?
User avatar
By Tachyon25
#56703
TheWaldorfer wrote:Of course you can via php (which is a standard for servers). There's no difference calling a php script from an ESP or any other app/program.

You'll need an own (hosted) server where php & MySQL is running plus a database & zable. For examples just google for "php & MySQL". There are ton's...

On the ESP-side just use

Code: Select allwget(yourdomain.com/examples/myscript.php?name=Peter&age=25)


which calls this example:

Code: Select all<?

$host = "MyDBServer.com";
$db = "dbname";
$user = "user";
$pw = "password";

$con = mysql_connect($host,$user,$pw) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES 'utf8'");

$name = $_GET["name"];
$age = $_GET["age"];

$res = mysql_query("Insert into Persons (name, age) VALUES ('$name', $age)");

print ("I have inserted $name and $age in my table");

?>


Note: Change mysql to mysqli in the script (servers which use MariaDB have slightly other sql-commands



Just one question, can you use the variables that you "GET" from MYSQL to use in Lua?
I would like to get certain values from my MYSQL database and then use it to change the outputs of ESP8266.