Jump to content

(Quest) No mysql query is running


Go to solution Solved by TMP4,

Recommended Posts

Hello friends.
I'm writing a quest but I couldn't run mysql commands at all.


local goldd = mysql_query("SELECT gold FROM player.player")
say_reward("Başarılı." , goldd)

Commands like SELECT - UPDATE do not work.

and it just gives this error:

attempt to call global `mysql_query' (a nil value)

I tried mysql_query
I tried mysql_query10
I tried mysql_direct_query
but the result is the same.

Link to comment
Share on other sites

  • Contributor

Add martysama's mysql_direct_query function to your source: https://www.google.com/search?q=mysql_direct_query+epvp+lollo_9_1
Then you can use local affected_rows, gold = mysql_direct_query("SELECT gold FROM player.player where id = 1")

Edited by TMP4
  • Good 1
Link to comment
Share on other sites

17 hours ago, TMP4 said:

Add martysama's mysql_direct_query function to your source: https://www.google.com/search?q=mysql_direct_query+epvp+lollo_9_1
Then you can use local affected_rows, gold = mysql_direct_query("SELECT gold FROM player.player where id = 1")

Thank you it worked.

SELECT gold FROM player.player WHERE account_id = 2

But it always shows the result as 1.

Link to comment
Share on other sites

  • Contributor
3 minutes ago, blaxis said:

Thank you it worked.

SELECT gold FROM player.player WHERE account_id = 2

But it always shows the result as 1.

 Use as I said: local affected_rows, gold = mysql_direct_query("SELECT gold FROM player.player where id = 2")

If you use only local gold, you will get the affected_rows's value only, despite the variable name. (Variable name does not matter, the gold will be the second value, and the affected rows will be the first one even if you name it as gold.)

Edited by TMP4
  • Good 1
Link to comment
Share on other sites

11 minutes ago, TMP4 said:

 Use as I said: local affected_rows, gold = mysql_direct_query("SELECT gold FROM player.player where id = 2")

If you use only local gold, you will get the affected_rows's value only, despite the variable name. (Only matter that it's the first, and the second)

 

local affected_rows, goldd = mysql_direct_query("SELECT gold FROM player.player WHERE account_id = '2';")
say_reward(tostring(goldd))

Not work.

 

Quest screen error:

table: 00xc66e bla bla bla

Edited by blaxis
Link to comment
Share on other sites

  • Bronze
4 hours ago, blaxis said:

 

local affected_rows, goldd = mysql_direct_query("SELECT gold FROM player.player WHERE account_id = '2';")
say_reward(tostring(goldd))

Not work.

 

Quest screen error:

table: 00xc66e bla bla bla

Since you are selecting, you are inserting information into two local variables. Information such as affected_rows and the values of those rows (affected_rows, goldd).
You can access the values from index 1 to (affected_rows) and the specific name.

Ex:

local affected_rows, goldd = mysql_direct_query("SELECT gold FROM player.player WHERE account_id = '2';")
say_reward(tostring(goldd[affected_rows]["gold"]))

In this example we are accessing table index by affected_rows because in our case you can only select the gold from account_id 2.

Edited by Braxy
  • Good 1

As long as I'll be a threat for you , i will always be your target :3

Link to comment
Share on other sites

14 hours ago, Braxy said:

Since you are selecting, you are inserting information into two local variables. Information such as affected_rows and the values of those rows (affected_rows, goldd).
You can access the values from index 1 to (affected_rows) and the specific name.

Ex:

local affected_rows, goldd = mysql_direct_query("SELECT gold FROM player.player WHERE account_id = '2';")
say_reward(tostring(goldd[affected_rows]["gold"]))

In this example we are accessing table index by affected_rows because in our case you can only select the gold from account_id 2.

Thanks!

Well, I want to ask one more thing. How can I use the result from the local=gold query in an if?

For example; if(gold) < 5 then...

Link to comment
Share on other sites

  • Contributor
  • Solution
local affected_rows, goldd = mysql_direct_query("SELECT gold FROM player.player WHERE name = '"..pc.get_name().."';"
local current_gold = goldd[affected_rows]["gold"]
say_reward(tostring(current_gold))
if current_gold < 5 then
	say_reward("You have less then 5 gold.")
else
	say_reward("You have 5 or more gold.")
end

I changed the query's WHERE from account_id to name because you could have up to 4 affected rows with account_id and
"goldd[affected_rows]["gold"]" would only return the last one that may not the current character.

For example if you have 4 character in your acc and uses account_id then the second character's gold is goldd[2]["gold"]).
Affected_rows returns the max value so it's always the lasts if you use that. If it's 1 like in my example, it is good to use, but you can replace it with 1 if you wish.

Edit: Anyone who just read this and thinking pc.get_gold() exists, well yes but this is just a query practice example 😅

Edited by TMP4
  • Good 1
Link to comment
Share on other sites

41 minutes ago, TMP4 said:
local affected_rows, goldd = mysql_direct_query("SELECT gold FROM player.player WHERE name = '"..pc.get_name().."';"
local current_gold = goldd[affected_rows]["gold"]
say_reward(tostring(current_gold))
if current_gold < 5 then
	say_reward("You have less then 5 gold.")
else
	say_reward("You have 5 or more gold.")
end

I changed the query's WHERE from account_id to name because you could have up to 4 affected rows with account_id and
"goldd[affected_rows]["gold"]" would only return the last one that may not the current character.

For example if you have 4 character in your acc and uses account_id then the second character's gold is : goldd[2]["gold"]).
Affected_rows returns the max value so it's always the lasts if you use that. If it's 1 like in my example, it is good to use, but you can replace it with 1 if you wish.

Edit: Anyone who just read this and thinking pc.get_gold() exists, well yes but this is just a query practice example 😅

Thank you so much.
It works flawlessly 🙂

Also yes functions like pc.get_gold could() be used but I had to do that with my query and now it's done. 🙂

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



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