Jump to content
  • 0

[paid if helped]Unable to return value from database to ingame


Calamity

Question

Hi, I'm working on something and for it to work in the manner that i require it. I need it to return a value from the database. It always returns a value of 0.

 

here's the function

function total_points(x)
local z = os.execute("mysql -u root account --execute='SELECT `points` FROM account.account WHERE id = ".. pc.get_account_id() ..";'")
return z
end

 

I've tested the query in navicat and it works fine, i can insert ints into the database but not strings??? 

 

 

i've tried using a mysql_query function but it wouldnt return any value. if someone has a working mysql_query function simlair to this, i'd appreciate if you could post it here as i could have used the wrong syntax for that.

 

any help is appreciated. 

 

I can't find any information on this so the first person to solve it gets 15 euros via Paypal, but i must be able to select any information and insert any rather than just inserting int's :).

 

information - i'm on 34k

server files -  im using are macross's

Link to comment
  • Answers 11
  • Created
  • Last Reply

Top Posters For This Question

Popular Days

11 answers to this question

Recommended Posts

  • 0

 

os.execute ([command])

This function is equivalent to the ANSI C function system. It passes command to be executed by an operating system shell. Its first result is true if the command terminated successfully, or nil otherwise. After this first result the function returns a string and a number, as follows:

    "exit": the command terminated normally; the following number is the exit status of the command.

    "signal": the command was terminated by a signal; the following number is the signal that terminated the command.

When called without a command, os.execute returns a boolean that is true if a shell is available.

You have to use a mysql_query function...

 

eg:

function mysql_query(text)
	local tmp=number(11111111,99999999)
	os.execute('mysql -u root -pPASSWORD -N -e '..string.format("%q",text)..' 2>&1 > /tmp/'..tmp)
	local res,i={},1
	local f,e=io.open("/tmp/"..tmp)
	if f then
		local line=f:read("*l")
		while line do
			res[i]={}
			string.gsub(line,"([^t]+)t*", function(s)
				table.insert(res[i],s)
			end)
			i=i+1
			line=f:read("*l")
		end
		f:close()
		os.execute("rm /tmp/"..tmp)
	end
	--[[if table.getn(res)==1 and table.getn(res[1])==1 then --only 1 variable returns
		res=res[1][1]
	end]]
	return res
end

And how-to use in quest:

--by ATAG
quest sqltest begin
	state start begin
		when 20016.chat."test list" begin
			local tbl=mysql_query("SELECT id, account_id, name from player.player LIMIT 10;")
			say("userlist: "..table.getn(tbl))
			for i,v in ipairs(tbl) do
				say(v[1].." "..v[2].." "..v[3])
			end
			say("")
		end
	end
end

$ uptime
1:26AM  up 732 days,  8:29, 1 user, load averages: 0.38, 0.31, 0.22

$ uname -srp
FreeBSD 9.1-RELEASE amd64

Link to comment
  • 0

Some mysqlclient version requires single dash, others need double dashes in the mysql options.

$ uptime
1:26AM  up 732 days,  8:29, 1 user, load averages: 0.38, 0.31, 0.22

$ uname -srp
FreeBSD 9.1-RELEASE amd64

Link to comment
  • 0

What is the output if you enter the command directly into console?

 

mysql -u root -p -N -e "SELECT id, account_id, name from player.player LIMIT 10;"

 

 

  • Love 1

$ uptime
1:26AM  up 732 days,  8:29, 1 user, load averages: 0.38, 0.31, 0.22

$ uname -srp
FreeBSD 9.1-RELEASE amd64

Link to comment
  • 0

Try this one, maybe you get some information:

function mysql_query(text)
    local tmp=number(11111111,99999999)
    os.execute('mysql -u root -pPASSWORD -N -e '..string.format("%q",text)..' 2>&1 > /tmp/'..tmp)
    local res,i={},1
    local f,e=io.open("/tmp/"..tmp)
    if f then
        local line=f:read("*l")
        while line do
            res[i]={}
            string.gsub(line,"([^t]+)t*", function(s)
                table.insert(res[i],s)
            end)
            i=i+1
            line=f:read("*l")
        end
        f:close()
        os.execute("rm /tmp/"..tmp)
    else
        res[1] = {(e or "WTF??")}
    end
    return res
end

or remove the os.execute("rm /tmp/"..tmp) and check the random number named file in /tmp

$ uptime
1:26AM  up 732 days,  8:29, 1 user, load averages: 0.38, 0.31, 0.22

$ uname -srp
FreeBSD 9.1-RELEASE amd64

Link to comment
  • 0

ok got it working, appreciated.

 

so how would i say

 

local totalX=mysql_query("SELECT points, FROM account.account WHERE id = ".. pc.get_account_id() ..";")
chat(totalX)

after i know this bit i can pay you the money, as then it'll all be solved :D

 

 

did test this but i cant see the syntax error :/

Link to comment
  • 0

ok got it working, appreciated.

 

so how would i say

 

local totalX=mysql_query("SELECT points, FROM account.account WHERE id = ".. pc.get_account_id() ..";")
chat(totalX)

after i know this bit i can pay you the money, as then it'll all be solved :D

 

 

did test this but i cant see the syntax error :/

 

Use this:

local totalX=mysql_query("SELECT points FROM account.account WHERE id = ".. pc.get_account_id() ..";")
chat(totalX.points[1])

 

Link to comment
  • 0

chat(totalX[1][1])

 

returns an indexed table. totalX[1] is the forst row, totalX[2] is 2nd, etc...

[1][1] is the first column in first roe, [1][2] is 2nd etc...

$ uptime
1:26AM  up 732 days,  8:29, 1 user, load averages: 0.38, 0.31, 0.22

$ uname -srp
FreeBSD 9.1-RELEASE amd64

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


×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.