Function like format, mysql_format
#1

Hi!
I want to use a function for mysql_query something like Function("UPDATE players SET money=%s where id=%d",name,id);
Can I make something like this?
I tried all what i know...
Reply
#2

You want "function" to do what "mysql_query" does?

If so (top of your script);

pawn Код:
#define Function mysql_query
Should work.
Reply
#3

pawn Код:
new query[256];
format(query, sizeof(query), "UPDATE %s SET %s = %d WHERE id = %d LIMIT 1", tablename, fieldname, value, sqlid);
mysql_query(query);
It's simple, just create a string, format it and query it!

You can also replace the '%s' %d etc with actual values.

Of course if you need to retrieve them, do it like you would in a string.

Have fun dude!
Reply
#4

You didn't understand what i want ...
I must to be more explicit...
I want a stock who combine mysql_format and mysql_query...
To execute query you must write only the query....
Function("UPDATE players SET age=%d where id=%d" age,id);
Reply
#5

pawn Код:
MySQL_SetInteger(sqlid, fieldname[], value, tablename[])
{
    new query[256];
    format(query, sizeof(query), "UPDATE %s SET %s = %d WHERE id = %d LIMIT 1", tablename, fieldname, value, sqlid);
    return mysql_query(query);
}
Reply
#6

Thanks a lot !
Reply
#7

No problem, but I'd advise only to use this when updating a single value.

It may cause lag if used excessively.
Reply
#8

Quote:

It may cause lag if used excessively.

Why?Is the same thing like
Quote:

format(query, sizeof(query), "UPDATE pl SET s = 5 WHERE id = 1 LIMIT 1");
mysql_query(query);

Why did you put there LIMIT 1?
Reply
#9

To limit the query to one update.
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)