Jump to content

Database connect problem


Recommended Posts

Posted


Hello guyz. I have the following problem: I have an mta:sa server, and
I'm trying to connect it to mysql, but it doesn't work. It
finds the table, but the table has records in it, which cannot be found.

Posted (edited)

Maybe the user you used to connect doesn't have SELECT privileges.

Edited by myonlake

If I helped you, please click the like button on the right ;) Thanks!

Posted
Guys this is the full script and the playerName, playerPassword, ID and the PlayerMoney are nil, what should I need to do?
 
local host = "hotstname..."
local username = "username..."
local password = "password..."
local db = "db_name"
local results = {}
local connection = dbConnect("mysql","dbname=dbname;host=hostname", username, password, "autoreconnect=1")
local qh = dbQuery(connection, "SELECT * FROM `asd` WHERE `ID` = ?", 1)
  local row = dbPoll(qh, -1)
  if (row) then
   for k, row in ipairs (row) do
  local id = tonumber(row["ID"])
  local playerName =  tostring(row["PlayerName"])
  local playerPassword = tostring(row["PlayerPassword"])
  local PlayerMoney = tonumber(row["PlayerMoney"])
  end
 end
  
Posted

You don't seem to be using the right database details in your snippet.

local host = "hotstname..."
local username = "username..."
local password = "password..."
local db = "db_name"
local connection = dbConnect("mysql", "dbname=" .. db .. ";host=" .. host, username, password)

if (connection) then
	local qh = dbQuery(connection, "SELECT * FROM `asd` WHERE `ID` = ?", 1)
	
	if (qh) then
		local result = dbPoll(qh, -1)

		if (result) then
			for _, row in ipairs(result) do
				local id = tonumber(row["ID"])
				local playerName = tostring(row["PlayerName"])
				local playerPassword = tostring(row["PlayerPassword"])
				local PlayerMoney = tonumber(row["PlayerMoney"])
			end
		end
	end
end

 

If I helped you, please click the like button on the right ;) Thanks!

Posted
1 hour ago, sahwel said:

Thank you so much :D

You're welcome!

If I helped you, please click the like button on the right ;) Thanks!

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...