Jump to content

DB Connection error


Smarting

Recommended Posts

Hello everyone, i have a problem.

I am not lua scripter, but somehow i managed to get trough some other errors, but this one is not understandable for me.

addEvent("acc:onPlayerSubmit", true)
addEventHandler("acc:onPlayerSubmit", getRootElement(),
function(username, pass, op, remember, autologin, email)
	if client then
		local ip, serial = getPlayerIP(client), getPlayerSerial(client)
		if op == 0 then --Logging in
			dbQuery(handlePlayerLogin, {client, username, pass, ip, serial, remember, autologin}, connection, "SELECT * FROM `accounts` WHERE username = ?", username)
		elseif op == 1 then --Registering
			if isValidEmail(email) then
				dbQuery(handlePlayerRegister, {client, username, pass, email, ip, serial, remember}, connection, "SELECT username FROM `accounts` WHERE username = ? OR email = ?", username, email)
			else
				triggerClientEvent(client, "acc:onSubmitFail", client, "Disposable emails are not allowed. Please use another email provider.")
			end
		end
	end
end)

Error code WARNING: account-manager/s_accounts.lua:209: Bad argument @ 'dbQuery' [Expected db-connection at argument 1, got nil]

Thanks! :)

Link to comment
  • Moderators

It means that the connection to the database has been failed. This connection is used for the code and the database to be able to communicate with each other.

 

In your code you should be looking for this function: dbConnect

https://wiki.multitheftauto.com/wiki/DbConnect

That is where the real problem starts.

You have either received an error about the dbConnect function or the dbConnect function has never been called.

 

 

 

Link to comment
20 hours ago, IIYAMA said:

It means that the connection to the database has been failed. This connection is used for the code and the database to be able to communicate with each other.

 

In your code you should be looking for this function: dbConnect

https://wiki.multitheftauto.com/wiki/DbConnect

That is where the real problem starts.

You have either received an error about the dbConnect function or the dbConnect function has never been called.

 

 

 

It has to be in the same file? or it can be in other file, cause in this file i did not find dbConnect.

Can i ask you show some kinda example? :D How to make connection?

And if in other file there is that connection, and if i add in other file same connection, is it slowing down server?

Like example: In this code i add dbConnect with details, and in other file is the same dbConnect, is it going to slow down system.

Link to comment
  • Moderators

It can be in another file but it has to be in the same resource.

Making a connection just with a new + empty database will not solve your problem. Containers(tables) for the data have be generated before you can store or load data.

If the connection function isn't in any of the files + there are no tables in the database, then it is recommended to consider it unfixable in case of not going to hire a paid scripter.

Link to comment

You can have a global database and resource conect it but you need to expprt the function to this resource ofc that is example you need table etc for working correct 

function connectToDatabase() 
  connection =dbConnect("sqlite", ":/global.db")
end 
addEventHandler("onResourceStart", resourceRoot, connectToDatabase) 

function getConnection () 
  return connection 
end 

 

Edited by Dimos7
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...