This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Read/write mysql database
#46
(19.11.2019, 14:07)admin Wrote: Example script. Map table keys are trend ID from external database, values are group addresses to get values from. Don't forget to change access details in connect function.
Code:
require('luasql.mysql')

env = luasql.mysql()
dbcon, err = env:connect(DB_NAME, USERNAME, PASSWORD, MYSQL_SERVER_IP, MYSQL_SERVER_PORT)

if dbcon then
  map = {
    [1] = '1/1/1',
    [2] = '1/1/2',
  }

  for id, addr in pairs(map) do
    value = grp.getvalue(addr)
    dbcon:execute('INSERT INTO trends_values (trend_id, value, created_at) VALUES (' .. id .. ', ' .. value .. ', NOW())') 
    dbcon:execute('UPDATE trends_definition SET updated_at=NOW() WHERE id=' .. id) 
  end

  dbcon:close()
else
  log('mysql connection failed ' .. tostring(err))
end

env:close()

This code creates the tables (trends_values, trends_definition) automatically or I must create it manually in the database?
Reply


Messages In This Thread
Read/write mysql database - by gjniewenhuijse - 14.01.2016, 09:49
RE: Read/write mysql database - by admin - 14.01.2016, 10:03
RE: Read/write mysql database - by RSV4 - 20.03.2016, 10:33
RE: Read/write mysql database - by admin - 21.03.2016, 06:59
RE: Read/write mysql database - by RSV4 - 21.03.2016, 09:59
RE: Read/write mysql database - by admin - 11.10.2016, 10:24
RE: Read/write mysql database - by g2g2g2 - 02.11.2016, 13:40
RE: Read/write mysql database - by g2g2g2 - 08.11.2016, 08:23
RE: Read/write mysql database - by admin - 08.11.2016, 08:26
RE: Read/write mysql database - by RSV4 - 06.12.2016, 23:08
RE: Read/write mysql database - by admin - 07.12.2016, 07:12
RE: Read/write mysql database - by RSV4 - 07.12.2016, 08:45
RE: Read/write mysql database - by admin - 07.12.2016, 09:09
RE: Read/write mysql database - by RSV4 - 07.12.2016, 09:27
RE: Read/write mysql database - by RSV4 - 18.12.2016, 00:05
RE: Read/write mysql database - by RSV4 - 18.12.2016, 07:58
RE: Read/write mysql database - by RSV4 - 18.12.2016, 10:28
RE: Read/write mysql database - by RSV4 - 11.01.2017, 23:19
RE: Read/write mysql database - by admin - 12.01.2017, 09:48
RE: Read/write mysql database - by RSV4 - 12.01.2017, 18:50
RE: Read/write mysql database - by FatMax - 17.02.2017, 12:45
RE: Read/write mysql database - by yeuwoo - 14.03.2017, 03:16
RE: Read/write mysql database - by admin - 14.03.2017, 06:53
RE: Read/write mysql database - by Thomas - 14.03.2017, 14:34
RE: Read/write mysql database - by admin - 05.09.2017, 13:50
RE: Read/write mysql database - by admin - 07.09.2017, 14:47
RE: Read/write mysql database - by pentadom - 18.11.2019, 16:54
RE: Read/write mysql database - by Daniel - 19.11.2019, 08:28
RE: Read/write mysql database - by pentadom - 19.11.2019, 09:37
RE: Read/write mysql database - by admin - 19.11.2019, 09:49
RE: Read/write mysql database - by pentadom - 19.11.2019, 10:22
RE: Read/write mysql database - by admin - 19.11.2019, 12:06
RE: Read/write mysql database - by pentadom - 19.11.2019, 12:23
RE: Read/write mysql database - by admin - 19.11.2019, 14:07
RE: Read/write mysql database - by pentadom - 19.11.2019, 19:12
RE: Read/write mysql database - by admin - 20.11.2019, 07:47
RE: Read/write mysql database - by pentadom - 17.05.2020, 08:18
RE: Read/write mysql database - by pentadom - 17.05.2020, 14:57
RE: Read/write mysql database - by Daniel - 18.05.2020, 07:38
RE: Read/write mysql database - by pentadom - 18.05.2020, 07:55
RE: Read/write mysql database - by admin - 18.05.2020, 07:50
RE: Read/write mysql database - by admin - 18.05.2020, 07:58
RE: Read/write mysql database - by pentadom - 18.05.2020, 08:01
RE: Read/write mysql database - by Daniel - 18.05.2020, 08:06
RE: Read/write mysql database - by pentadom - 18.05.2020, 08:08
RE: Read/write mysql database - by pentadom - 19.05.2020, 16:08
RE: Read/write mysql database - by admin - 20.05.2020, 07:38
RE: Read/write mysql database - by pentadom - 20.05.2020, 16:27

Forum Jump: