問題描述:畢業設計中用到了Luasql來Mysql資料庫,Lua用的是用源碼自己編譯的,測試代碼類似於下面:
-- load driverrequire "luasql.mysql"-- create environment objectenv = assert (luasql.mysql())-- connect to data sourcecon = assert (env:connect("database", "usr", "password", "192.168.xx.xxx", 3306))-- reset our tableres = con:execute"DROP TABLE people" --建立新表peopleres = assert (con:execute[[CREATE TABLE people( name varchar(50), email varchar(50))]])-- add a few elementslist = {{ name="Jose das Couves", email="jose@couves.com", },{ name="Manoel Joaquim", email="manoel.joaquim@cafundo.com", },{ name="Maria das Dores", email="maria@dores.com", },}for i, p in pairs (list) do --加入資料到people表res = assert (con:execute(string.format([[ INSERT INTO people VALUES ('%s', '%s')]], p.name, p.email)))end-- retrieve a cursorcur = assert (con:execute"SELECT name, email from people") --擷取資料-- print all rowsrow = cur:fetch ({}, "a") -- the rows will be indexed by field names --顯示出來while row doprint(string.format("Name: %s, E-mail: %s", row.name, row.email))row = cur:fetch (row, "a") -- reusing the table of resultsend-- close everythingcur:close()con:close()env:close()
通過類似上面的方法串連,程式會在
row = cur:fetch ({}, "a")
傳入參數為 “a”的時候crash掉,百度了N久找不到原因。後來在一個CMUD的論壇上看了可能的問題,
解決方案:
Lua5.1 的DLL檔案有兩個,一個是 Lua5.1.DLL,一個是Lua51.DLL,
用源碼編譯Lua的時候,編譯出來的有問題,
用官方編譯出來的Lib以靜態庫的形式連結就沒有問題了。