2

I want to use prepared statements in my lua scripts. As mentioned in my previous post, people recommend using lua-dbi. Unfortunately there is little documentation available. I just need a basic script that connects to the database with credentials, and use prepared statements (prefered with a bind function to names in the query). Anyone experienced with this?

Community
  • 1
  • 1

1 Answers1

2

You can find it on the project's wiki pages:

Establishing connection: https://code.google.com/p/luadbi/wiki/DBDDriverConnection

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()

where, you'd update the part dbh:prepare as per your needs.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • On ubuntu I installed lua dbi with: sudo apt-get install lua-dbi-mysql. But I get the message "module 'DBI' not found:" –  Sep 20 '15 at 11:07
  • i changed first line to "require('dbi')" and then it throws: "./dbi.lua:4: too many C levels (limit is 200) in main function near ''MySQL''" –  Sep 20 '15 at 11:11
  • really no idea how to solve this. The github link in the question of the link is not working :/ –  Sep 20 '15 at 11:30