Jump to content

Problems with mysql connection


dam034

Recommended Posts

Dear users,

I created a test resource called "prova". When I try to start it, I get this error:

[12:50:25] start: Requested by Console
[12:50:25] Resource 'prova' changed, reloading and starting
[12:50:25] Starting prova
[12:50:25] WARNING: [mie]/prova/mysql.lua:4: Bad usage @ 'dbConnect' [Can't connect to local MySQL s
erver through socket '' (111)]
[12:50:25] start: Resource 'prova' started

As it appears, the problem is in the mysql.lua file, executed serverside, this is the code:

db = nil

function conn()
db = dbConnect('mysql', 'dbname=mtasa;host=localhost;port=3306;', 'mtasa', '', "share=1")
end

function disc()
destroyElement(db)
end

function segnalo(msg, tipo)
dbExec(db, 'INSERT INTO provatab(testo, soldi, spotf) VALUES(?, ?, ?)', 'Msg-'..tostring(tipo)..': '..msg, 2500, 1)
end

function giraarma(prima, mo)
dbExec(db, 'INSERT INTO provatab(testo, soldi, spotf) VALUES(?, ?, ?)', 'Arma da '..tostring(prima)..' a '..tostring(mo)..' - Chi: '..getPlayerName(source), 2500, 1)
end



addEventHandler('onResourceStart', getResourceRootElement(), conn)
addEventHandler('onResourceStop', getResourceRootElement(), disc)
addEventHandler("onPlayerChat", getRootElement(), segnalo)
addEventHandler("onPedWeaponSwitch", getRootElement(), giraarma)

I thought it could be a mysql problem, but when I try to access to my database via phpmyadmin on localhost server, I can access without problems.

 

What can it be?

 

Please help!

Link to comment

Actually, I'm developing/testing my MTA server in LAN, then without public IP, and then I don't want to grant mysql connections outside localhost, due to security problems.

How can I fix this issue (unix socket) using localhost address?

 

Thanks

Link to comment

I solved the problem changing the old dbConnect() code with this:

db = dbConnect('mysql', 'dbname=mtasa;host=localhost;port=3306;unix_socket=/var/run/mysqld/mysqld.sock;charset=utf8;', 'mtasa', '', "share=1;autoreconnect=1;")

 

Now if you want, you can trash this topic.

Bye!

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...