Raised This Month: $ Target: $400
 0% 

Getting a field using MySQL


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
.Prometheus.
Member
Join Date: Sep 2004
Old 10-12-2004 , 11:25   Getting a field using MySQL
Reply With Quote #1

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.
.Prometheus. is offline
Send a message via AIM to .Prometheus. Send a message via MSN to .Prometheus.
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 10-12-2004 , 12:13  
Reply With Quote #2

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 }
Johnny got his gun is offline
.Prometheus.
Member
Join Date: Sep 2004
Old 10-12-2004 , 13:09  
Reply With Quote #3

Is there any way to do it with mysql? As dbi pwns me.
.Prometheus. is offline
Send a message via AIM to .Prometheus. Send a message via MSN to .Prometheus.
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 10-12-2004 , 16:28  
Reply With Quote #4

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
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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