Raised This Month: $ Target: $400
 0% 

MySQL Prob


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
BAILOPAN
Join Date: Jan 2004
Old 05-31-2004 , 13:39   Re: MySQL Prob
Reply With Quote #3

Just a note for 0.20 DBI will look like this (don't do this now, keep it in mind):

Code:
public pay() {     client_print(0,3,"Test:1");     new players[32], inum     get_players(players,inum);     for(new i = 0; i < inum; i++)     {         client_print(i,3,"Test:2");         if(minuteI[i])         {             client_print(i,3,"Test:3");             new authid[32],query[256];             get_user_authid(i,authid,31);             format(query,255,"SELECT balance FROM money WHERE steamid='%s'",authid);             new res = dbi_query(mysql, query)             if(res < 0)             {                 server_print("Query failed!");                 return PLUGIN_HANDLED;             }             new strBalance[32],strIncome[32];             if(dbi_nextrow(mysql, res) > 0)             {                 client_print(i,3,"Test:4");                 dbi_result(mysql, res, "balance", strBalance, 31)                 dbi_result(mysql, res, "income", strIncome, 31)                 new balance = str_to_num(strBalance)                 new inc = str_to_num(strIncome);                 format(query,255,"UPDATE money SET balance = %i WHERE steamid='%s'",balance+inc,authid);                 client_print(i,3,"Balance: %i | Income: %i  | Balance + Income: %i / %s",balance,inc,balance+inc,authid)                 dbi_free_result(res)                 if(dbi_query(mysql,query) < 0)                 {                         server_print("Query failed!");                         return PLUGIN_HANDLED;                 }             }         }     }     return PLUGIN_HANDLED; }

Relevant changes:
You access fields by name, not by row
mysql_query returns 0 on SUCCESS if it has NO RESULT
mysql_query returns a RESULT HANDLE to access results or a NEGATIVE NUMBER for failure.
You use a RESULT HANDLE to get result specific information - this will let up execute multiple queries in loops.
You must free the result of any query.

This makes it similar to PHP's method, but it breaks a lot of backward compatibility.
__________________
egg
BAILOPAN is offline
 



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 07:02.


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