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
#59
Hello,

I did some tests with the next code. I want to insert all the trending values in my SQL database. When I run the script all the code executes correctly without errors in the logs but in the database I don't see the new values..  Sad

Code:
require('trends')
require("luasql.mysql");

--Get a list of all trendings
names = db:getlist('SELECT name FROM trends')

log (names)

--Defines a period of the last day
dates = {}
dates['start'] = os.date('*t')
dates['start'].day = dates['start'].day - 1
dates['end'] = os.date('*t')


env = luasql.mysql();
--DATABASE CONNECTION -> (DB_NAME, USERNAME, PASSWORD, MYSQL_SERVER_IP, MYSQL_SERVER_PORT)
dbcon, err = env:connect('CONFIDENTIAL', 'admin','CONFIDENTIAL', 'lm-database.CONFIDENTIAL.us-east-1.rds.amazonaws.com', '3306');
log(dbcon, err)

if dbcon then

  -- Iterates all the trendings
  for _, name in ipairs(names) do
   
    -- Get all the trending values
    data = trends.fetch(name, dates)
   
    -- Iterates all the trending values
    for id, val in pairs(data) do

      -- Insert the trending values in the database.
      dbcon:execute('INSERT INTO trending-definition (id, value) VALUES (id,val)') 

    end

  end

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

I'm not a programmer and It's my first time doing a script with LUA so I apologize in advance for the posible errors.
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: