MySQL - Anyone spare a minute? -
GamingTurf - 29.11.2011
Right, i would like to grab the following:
'ip' from
'users'.
So it would be
SELECT 'ip' FROM 'users' WHERE 'username' = %s. Yep? Got that.
Now, i have done the query.
How do i store this? I can't seem to figure it out, i want to store it in:
new OBanIP[25]; - This is at the top of the command.
+rep will be given, and i hope you can help me!
Thanks!
Re: MySQL - Anyone spare a minute? -
GamingTurf - 29.11.2011
Anyone?
Re: MySQL - Anyone spare a minute? -
BlackBank - 29.11.2011
You could try this:
pawn Code:
mysql_get_field(OBanIP, "ip");
Re: MySQL - Anyone spare a minute? -
GamingTurf - 29.11.2011
Quote:
Originally Posted by BlackBank3
You could try this:
pawn Code:
mysql_get_field(OBanIP, "ip");
|
Hey, i have already tried that, and i got this error:
Code:
[19:03:37] CMySQLHandler::FetchField(ip) - You cannot call this function now. (Reason: Fields/Rows are empty.)
Do you have MSN? And you could assist me with TeamViewer (if you dont mind!
).
Thanks for the reply.
Re: MySQL - Anyone spare a minute? -
BlackBank - 29.11.2011
EDIT: My fault i see the query already.
Respuesta: MySQL - Anyone spare a minute? -
OPremium - 29.11.2011
pawn Code:
new query[70];
GetPlayerName(playerid, query, sizeof(query));
mysql_format(1, query, "SELECT ip FROM users WHERE username = '%e';", query);
mysql_query(query, 1/*resultid*/, playerid, 1);
//^ Put that in the function/callback where you want to call the query
public OnQueryFinish( query[], resultid, extraid, connectionHandle )
{
if(resultid == 1)
{
mysql_store_result();
mysql_retrieve_row();
mysql_get_field("ip", OBanIP);
//Whatever you want to do with the IP... Here "extraid" = playerid
mysql_free_result(); //DON'T forget this! Or you will get "commands out of sync" error
}
}
If you have multiple threaded queries you will most likely need to change the
resultid to an available one
Also, check this: https://sampwiki.blast.hk/wiki/MySQL for documentation of the plugin's natives and some useful examples
Re: MySQL - Anyone spare a minute? -
Calgon - 29.11.2011
Threads aren't required, but you can't, in SQL, select fields by using a single apostrophe, you need to use a grave (`) or none at all.
Also, make sure you use mysql_store_result() after querying, then mysql_retrieve_row() to get the specific row.
Re: MySQL - Anyone spare a minute? -
Scenario - 29.11.2011
Quote:
Originally Posted by GamingTurf
Hey, i have already tried that, and i got this error:
Code:
[19:03:37] CMySQLHandler::FetchField(ip) - You cannot call this function now. (Reason: Fields/Rows are empty.)
|
Are you sure everything is saving?
Quote:
Originally Posted by Calgon
Threads aren't required
|
No, but recommended.
I use 'em all the time now.
Re: MySQL - Anyone spare a minute? -
GamingTurf - 29.11.2011
Wow, thanks for all the help guys - /oban now works fine.
Butt, i've now tried making /omute, i thought i wouldn't have any problems - i was wrong:
pawn Code:
format(checkquery, sizeof(checkquery), "SELECT `muted` FROM `users` WHERE `username` = '%s'", OBanName);
mysql_query(checkquery);
mysql_store_result();
mysql_retrieve_row();
mysql_get_field("muted", IsMutedOrNot); --- Error line ----
mysql_free_result();
Error:
Code:
error 035: argument type mismatch (argument 1)
Thanks, if your able to help!
I have, new IsMutedOrNot;
:S.
Re: MySQL - Anyone spare a minute? -
Scenario - 29.11.2011
Which MySQL plugin are you using?
Re: MySQL - Anyone spare a minute? -
GamingTurf - 29.11.2011
G-Stylezz, i think.
Re: MySQL - Anyone spare a minute? -
Calgon - 29.11.2011
Quote:
Originally Posted by GamingTurf
Wow, thanks for all the help guys - /oban now works fine.
Butt, i've now tried making /omute, i thought i wouldn't have any problems - i was wrong:
Error:
Code:
error 035: argument type mismatch (argument 1)
Thanks, if your able to help!
I have, new IsMutedOrNot;
:S.
|
mysql_get_field probably is expecting a string as the second parameter.
pawn Code:
new szUnload[10], IsMutedOrNot;
format(checkquery, sizeof(checkquery), "SELECT `muted` FROM `users` WHERE `username` = '%s'", OBanName);
mysql_query(checkquery);
mysql_store_result();
mysql_retrieve_row();
mysql_get_field("muted", szUnload); --- Error line ----
mysql_free_result();
IsMutedOrNot = strval(szUnload);
Also, as Vince said, you can use mysql_fetch_int which would be more relevant.
Re: MySQL - Anyone spare a minute? -
Vince - 29.11.2011
If you're only fetching a single item from the database at a time - be it a string, integer or float - it is recommended to use
mysql_fetch_row,
mysql_fetch_int and
mysql_fetch_float respectively.
Re: MySQL - Anyone spare a minute? -
GamingTurf - 29.11.2011
Quote:
Originally Posted by Calgon
mysql_get_field probably is expecting a string as the second parameter.
pawn Code:
new szUnload[10], IsMutedOrNot;
format(checkquery, sizeof(checkquery), "SELECT `muted` FROM `users` WHERE `username` = '%s'", OBanName); mysql_query(checkquery); mysql_store_result(); mysql_retrieve_row(); mysql_get_field("muted", szUnload); --- Error line ---- mysql_free_result(); IsMutedOrNot = strval(szUnload);
Also, as Vince said, you can use mysql_fetch_int which would be more relevant.
|
Thank you alot!
Thanks to everyone who replied too!
.