Lua插入声明

时间:2014-04-18 07:45:44

标签: mysql lua luasql

我的插入声明有问题:

Create = function (LN,FN,Add,Tel,Cell)
    LastName = tostring(LN);
    FirstName = tostring(FN);
    Address = tostring(Add);
    Telephone =tostring(Tel); 
    Cellphone = tostring(Cell);

- 问题的根源

conn:execute([[INSERT INTO book(LastName, FirstName, Address, Telephone, Cellphone) VALUES ("]]"'"LastName"','"FirstName"','" Address"','" Telephone"','" Cellphone")]]'")

 print ("\n Creating an account Successful")
 end 

1 个答案:

答案 0 :(得分:3)

我建议你使用string.format来放置数据:

Create = function (LN,FN,Add,Tel,Cell)
    local LastName, FirstName, Address, Telephone, Cellphone = tostring(LN), tostring(FN), tostring(Add), =tostring(Tel), tostring(Cell)
    local sQuery = [[INSERT INTO book(LastName, FirstName, Address, Telephone, Cellphone) VALUES ('%s', '%s', '%s', '%s', '%s')]]
    conn:execute( sQuery:format(LastName, FirstName, Address, Telephone, Cellphone) )