Smarting

DB Connection error

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! :)

Share this post


Link to post

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.

 

 

 

Share this post


Link to post
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.

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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.