Connect to MySQL with luasql

Source: Internet
Author: User

Problem description: luasql is used for MySQL databases in the graduation project. Lua uses its own source code. The test code is similar to the following:

-- 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" -- create a new table 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 -- add data to the people table 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") -- get data -- print all rowsrow = cur: Fetch ({}, "A") -- The Rows will be indexed by field names -- the 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 ()

Connect through a method similar to the above, the program will

row = cur:fetch ({}, "a")

Crash is dropped when the input parameter is "A". Baidu cannot find the cause after N years. Later I saw possible problems on a cmud forum,

Solution:

Lua5.1 has two DLL files: lua5.1.dll and lua51.dll,

When compiling Lua with the source code, there is a problem with the compilation,

It is no problem to link the Lib compiled by the official team to a static library.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.