【发布时间】:2015-12-17 03:10:36
【问题描述】:
我想在我的 lua 脚本中使用准备好的语句。正如我之前的post 中提到的,人们推荐使用lua-dbi。不幸的是,几乎没有可用的文档。我只需要一个使用凭据连接到数据库的基本脚本,并使用准备好的语句(最好使用绑定函数来绑定查询中的名称)。有没有人遇到过这种情况?
【问题讨论】:
标签: database lua prepared-statement luasql
我想在我的 lua 脚本中使用准备好的语句。正如我之前的post 中提到的,人们推荐使用lua-dbi。不幸的是,几乎没有可用的文档。我只需要一个使用凭据连接到数据库的基本脚本,并使用准备好的语句(最好使用绑定函数来绑定查询中的名称)。有没有人遇到过这种情况?
【问题讨论】:
标签: database lua prepared-statement luasql
您可以在项目的 wiki 页面上找到它:
建立连接: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()
在哪里,您可以根据需要更新dbh:prepare 部分。
【讨论】: