Logic Machine Forum
Read/write mysql database - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Read/write mysql database (/showthread.php?tid=193)

Pages: 1 2 3 4


Read/write mysql database - gjniewenhuijse - 14.01.2016

Is it possible to query/insert data into a Mysql database in a LM4?


RE: Read/write mysql database - admin - 14.01.2016

Install packages:
https://dl.openrb.com/pkg/zlib_1.2.7-1_mxs.ipk
https://dl.openrb.com/pkg/libmysqlclient_5.1.73-1_mxs.ipk
https://dl.openrb.com/pkg/liblua-mysql_2.2.0-2_mxs.ipk

Docs:
http://keplerproject.github.io/luasql/doc/us/manual.html

Short example, don't use db as a variable name or you will mess up LM internal database connection

Code:
require('luasql.mysql')

env = luasql.mysql()
dbcon = env:connect(DB_NAME, USERNAME, PASSWORD, MYSQL_SERVER_IP, MYSQL_SERVER_PORT)
cursor = dbcon:execute('SELECT * FROM mytable')

while true do
  row = cursor:fetch({}, 'a')

  if row then
    log(row)
  else
    break
  end
end

cursor:close()
dbcon:close()
env:close()



RE: Read/write mysql database - gjniewenhuijse - 14.01.2016

perfect, it works!


RE: Read/write mysql database - RSV4 - 20.03.2016

Hi,
are these the correct packages for the LM3 Reactor?
Thanks


RE: Read/write mysql database - admin - 21.03.2016

Yes, you can use them on all devices except for Load Balancer and old LM2.


RE: Read/write mysql database - RSV4 - 21.03.2016

Great, thank you!


RE: Read/write mysql database - gjniewenhuijse - 11.10.2016

i have problems using mysql in the latest beta version


RE: Read/write mysql database - admin - 11.10.2016

Yes, older packages will not work. Please install these:
https://dl.openrb.com/lm-16.09-rc2/pkg/zlib_1.2.7-1_mxs.ipk
https://dl.openrb.com/lm-16.09-rc2/pkg/libmysqlclient_5.1.73-1_mxs.ipk
https://dl.openrb.com/lm-16.09-rc2/pkg/liblua-mysql_2.2.0-4_mxs.ipk


RE: Read/write mysql database - gjniewenhuijse - 11.10.2016

(11.10.2016, 10:24)admin Wrote: Yes, older packages will not work. Please install these:
https://dl.openrb.com/lm-16.09-rc2/pkg/zlib_1.2.7-1_mxs.ipk
https://dl.openrb.com/lm-16.09-rc2/pkg/libmysqlclient_5.1.73-1_mxs.ipk
https://dl.openrb.com/lm-16.09-rc2/pkg/liblua-mysql_2.2.0-4_mxs.ipk

thanks, it works.


RE: Read/write mysql database - g2g2g2 - 02.11.2016

Hey, how can i write from my LM to mysql?
docs - error 404!

sorry for my bad english...


RE: Read/write mysql database - gjniewenhuijse - 02.11.2016

(02.11.2016, 13:40)g2g2g2 Wrote: Hey, how can i write from my LM to mysql?
docs - error 404!

sorry for my bad english...

require('luasql.mysql')
env = luasql.mysql()
dbcon = env:connect('db', 'user', 'password', 'host', 'port')
if dbcon then
  cursor = dbcon:execute( 'your sql statement' ) 
  dbcon:close()
  env:close()
end


RE: Read/write mysql database - g2g2g2 - 08.11.2016

hey.. it not work!
i have LM4 reactor lite
all lib install successful

here is my script

require("luasql.mysql");
env = assert(luasql.mysql());
log(env); -- // answer is "MySQL environment (0xb6ed5fa0)"
dbcon = env:connect('base_test', 'root','pass', '192.168.1.40');
log(dbcon); -- // answer is "nil"
cursor = dbcon:execute ( 'INSERT INTO devices (name) VALUES (\"test1\")' );
dbcon:close();
env:close();


RE: Read/write mysql database - admin - 08.11.2016

Try this, it should tell you what's going on. Most probably your user cannot access the database remotely (privileges).
Code:
dbcon, err = env:connect('base_test', 'root','pass', '192.168.1.40')
log(dbcon, err)



RE: Read/write mysql database - RSV4 - 06.12.2016

(14.01.2016, 10:03)admin Wrote: Install packages:
https://dl.openrb.com/pkg/zlib_1.2.7-1_mxs.ipk
https://dl.openrb.com/pkg/libmysqlclient_5.1.73-1_mxs.ipk
https://dl.openrb.com/pkg/liblua-mysql_2.2.0-2_mxs.ipk

Docs:
http://keplerproject.github.io/luasql/doc/us/manual.html
The packages are no longer available? 404?


RE: Read/write mysql database - admin - 07.12.2016

All available packages can be found here:
https://dl.openrb.com/lm-16.09/pkg/


RE: Read/write mysql database - RSV4 - 07.12.2016

Thank you! Do I need to have the latest firmware for this packages? And where do I see the current firmware the LM is running?


RE: Read/write mysql database - admin - 07.12.2016

These are the same packages that come with the latest release firmware. Some are not installed by default (like MySQL) or are model-dependent. Current version can be seen in LM interface bottom left corner.


RE: Read/write mysql database - RSV4 - 07.12.2016

Ok, will update to the latest firmware and then install the MySQL packages.


RE: Read/write mysql database - RSV4 - 18.12.2016

Now running FW 20160927, but for all three packages I get the error "Update package file is invalid" when I try to install them (on the start page I go to "Logic Machine", enter my credentials, then go to "Utilities" tab, click "Install updates", click browse, select one of the three files, click "Save", then the "Update package file is invalid" message appears). What am I doing wrong? Thanks!


RE: Read/write mysql database - Erwin van der Zwart - 18.12.2016

Hi,

You follow the wrong steps (:

Packages can be installed by system config -> system -> packages -> action -> + and browse to add package.

Or with script with a os.execute command. (HL and SL can only be done through script as the menu options to install and remove packages are not default enabled in our FW)

BR,

Erwin