3

Apache 2.4.4(mod_luaモジュールが付属しています)をダウンロードしてインストールしました。次のように有効にしました。

--httpd.conf--

LoadModule lua_module modules/mod_lua.so
AddHandler lua-script .lua

簡単なスクリプトを実行すると、機能します。

--htdocs / hello.lua--

function handle(r)
    r.content_type = "text/html"
    r:puts("Hello Lua World!\n")
end

ローカルのpgデータベースに接続したいのですが、動作しません。

function handle(r)
    r.content_type = "text/html"
    r:puts("Hello Lua World!\n")
    local db, err = r:dbacquire("postgres", "postgres://user:secret@localhost/db0")
    if not err then
     r:puts("connected!")
    else
     r:puts("couldn't connect!")
    end
end

エラーメッセージは一切ありません。それ以上の構成がありませんか?

ご入力いただきありがとうございます。

4

2 に答える 2

0

ドライバー名と接続文字列が間違っていることがわかりました。質問の dbacquire 行をこれに置き換えると、機能するはずです。

db = r:dbacquire("pgsql", "hostname=localhost dbname=foo user=bar password=baz")

さらに良いことに、これらを httpd.conf に埋め込むことで、

DBDriver pgsql
DBDParams "hostname=localhost dbname=foo user=bar password=baz"

luaスクリプトでこれを行うだけで逃げることができます

db = r:dbacquire()
--start using your db here
于 2013-03-22T14:05:37.083 に答える