Luasql错误:“LuaSQL:连接到数据库的错误” [英] Luasql error: "LuaSQL: error connecting to database"

查看:111
本文介绍了Luasql错误:“LuaSQL:连接到数据库的错误”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mysql。我试图使用Luasql接入mysql数据库。我已经安装Luasql使用yum。然后我尝试下面的代码:

I am working on mysql. I am trying to acess the mysql database using the Luasql.I have installed Luasql using yum. Then i tried the following code:

mysql = require "luasql.mysql"

env = assert(mysql.mysql())

con = assert(env:connect ( "db_name", "username", "password", "localhost"))

for no, name in rows (con, "select * from t1") do

print (string.format ("%s", name))

end

执行上述代码时出现以下错误:

While executing the above code i am getting the following error :

lua: check.lua:3: LuaSQL: error connecting to database. MySQL: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
stack traceback:
    [C]: in function 'assert'
    check.lua:3: in main chunk
    [C]: ?

如何克服这个错误。任何人都可以帮助我正确执行代码?谢谢!!!

How to overcome this error.Can anyone help me for the proper execution of the code? Thanks !!!

推荐答案

这段代码执行得很好...为什么@ EgorSkriptunoff& jaylzhang for ur responses

This code executes well..thank u both @ EgorSkriptunoff &jaylzhang for ur responses

mysql = require "luasql.mysql"
env = assert(mysql.mysql())
con = assert(env:connect ( "db_name", "username", "password", "hostname", "3306"))
local cur = con:execute("select * from t1")
local row = cur:fetch({}, 'a')
for k, v in pairs(row) do
    print(k, v)
end

这篇关于Luasql错误:“LuaSQL:连接到数据库的错误”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆