- Tue Oct 18, 2016 11:50 am
#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.