【问题标题】:How to use prepared statements in lua-dbi?如何在 lua-dbi 中使用准备好的语句?
【发布时间】:2015-12-17 03:10:36
【问题描述】:

我想在我的 lua 脚本中使用准备好的语句。正如我之前的post 中提到的,人们推荐使用lua-dbi。不幸的是,几乎没有可用的文档。我只需要一个使用凭据连接到数据库的基本脚本,并使用准备好的语句(最好使用绑定函数来绑定查询中的名称)。有没有人遇到过这种情况?

【问题讨论】:

    标签: database lua prepared-statement luasql


    【解决方案1】:

    您可以在项目的 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 部分。

    【讨论】:

    • 在 ubuntu 上我安装了 lua dbi:sudo apt-get install lua-dbi-mysql。但我收到消息“找不到模块'DBI':”
    • 我将第一行更改为“require('dbi')”然后它抛出:“./dbi.lua:4: too many C levels (limit is 200) in main function near '' MySQL''"
    • 真的不知道如何解决这个问题。链接问题中的github链接不起作用:/
    猜你喜欢
    • 2014-04-17
    • 2016-04-18
    • 1970-01-01
    • 2014-03-07
    • 1970-01-01
    • 2012-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多