AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Getting a field using MySQL (https://forums.alliedmods.net/showthread.php?t=6723)

.Prometheus. 10-12-2004 11:25

Getting a field using MySQL
 
It's just stumped me, I know how to do it, but it jsut isn't working, I'm probably doing it wrong.

What I need to do is select a part of a table and the bit in the table will be either 1 or 0, I then get it using mysql_getfield and str_to_num it, the thing is, every time I use the command, I get "MySQL: unkown error" printed to the server console. This is the code:

if(!mysql)
mysqlConnect();

new name[33],query[256],authid[32];
get_user_name(id,name,32);
get_user_authid(id,authid,32);
format(query,255,"SELECT cop FROM users WHERE steamid='%s'",authid);
mysql_query(mysql,query);
new Str[256];
mysql_getfield(mysql,1,Str,255);
new is_cop = str_to_num(Str);
if(is_cop > 0){

And I can connect to the db. No problems there.

Johnny got his gun 10-12-2004 12:13

Use dbi.inc instead.

When you connect, you get a resource handle to the db connection. Use it to address queries, for disconnecting etc. When you query, you get a resource handle to the query result set. Use that handle when getting data from the query result, not the handle to the db connection. Once you are done getting whatever data you need from the query result resource handle, use dbi_free_result() on it. More info in dbi.inc.

Code:
new Sql:handleConnection = dbi_connect(blablabla) new Result:handleResult = dbi_query(handleConnection, "SELECT * FROM blablablabla") for(new i = 1; dbi_nextrow(handleResult); i++) { dbi_field(handleResult, 1, storeresulthere) // gets data from 1st field }

.Prometheus. 10-12-2004 13:09

Is there any way to do it with mysql? As dbi pwns me.

devicenull 10-12-2004 16:28

I wrote a nice example of dbi, you can find it in one of the sticky links.. "Small scripting tutorials", iirc

Edit: http://forums.alliedmods.net/showthr...?p=42838#45304


All times are GMT -4. The time now is 17:26.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.