Sign in to follow this  
sahwel

Database connect problem

Recommended Posts


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.

Share this post


Link to post

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

Edited by myonlake

Share this post


Link to post

For get records from database you need 

dbQuery
dbPoll 

 

Share this post


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

Share this post


Link to post

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

 

Share this post


Link to post
1 hour ago, sahwel said:

Thank you so much :D

You're welcome!

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.