-->
Page 1 of 1

Connecting directly to MySQL

PostPosted: Thu Jun 23, 2016 3:34 pm
by Dennis Jenen
Hey

I got the NodeMcu ESP8266 version 12 and V3 (I think)

I got it flashed an running Lua, following this tutorial https://learn.adafruit.com/adafruit-huz ... odemcu-lua

I got the LUA for GPIO, WiFi and connection to a homepage working.
BUT...
Now, Im trying to transfer data to a MySQL. I have seen someone do this by GET or POST to a homepage, but I have seen LuaSQL and luadbi with download from: https://code.google.com/archive/p/luadbi/downloads

My question is, how to I get the luadbi working (code below)? Im guessing I have to upload the dll and use it somehow
require('DBI')

-- Create a connection
local dbh = assert(DBI.Connect('Driver', db, username, password, host, port))

-- set the autocommit flag
-- this is turned off by default
dbh:autocommit(true)

-- check status of the connection
local alive = dbh:ping()

-- prepare a connection
local sth = assert(dbh:prepare(sql_string))

-- commit the transaction
dbh:commit()

-- finish up
local ok = dbh:close()


Alternative, but just as fine from my point of view:
Using the ODBC driver from https://github.com/moteus/lua-odbc/tree/master/lua
with the following code:

local odbc = require "odbc.dba"
local cnn = odbc.Connect{
Driver ='{MySQL ODBC 5.2 ANSI Driver}';
db='test';
uid='root';
};
local stmt = cnn:prepare"INSERT INTO pet values(:NAME,:AGE)"
stmt:exec{NAME = "swaroop", AGE = 12}


OR, There is some way of connecting to a MySQL, that I dont know => Not on first page of google searches...

THANKS everyone.
Dennis

Re: Connecting directly to MySQL

PostPosted: Tue Jun 28, 2016 8:11 pm
by cmisztur
Dennis, it will be much simpler if you introduce a HTTP API into mysql, such as this: https://www.infoq.com/news/2014/09/MySQL-REST.

And then make HTTP calls into db.

/c