AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem with SQL... (https://forums.alliedmods.net/showthread.php?t=61947)

AceDude 10-14-2007 15:15

Problem with SQL...
 
This error is killing me. I have tried to make query in ~5 diffrent ways, but its always same (invalid handle).

Code:

L 10/14/2007 - 21:07:18: [MySQL] Invalid DBI result handle 2
L 10/14/2007 - 21:07:18: [AMXX] Displaying debug trace (plugin "csn-sql.amxx")
L 10/14/2007 - 21:07:18: [AMXX] Run time error 10: native error (native "dbi_nextrow")
L 10/14/2007 - 21:07:18: [AMXX]    [0] csn-sql.sma::client_putinserver (line 112)

Code listing:
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <dbi>

#define MAX_PLAYERS 32

new bool:g_restart_attempt[MAX_PLAYERS 1]
new 
Sql:dbc
new plr_points[32]


public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("ResetHUD""event_hud_reset""be")
    
register_clcmd("fullupdate""clcmd_fullupdate"
    
register_event("TextMsg""event_restart_attempt""a""2=#Game_will_restart_in")
    
    
sql_init() 
}

public 
sql_init() {
    new 
host[64], username[32], password[32], dbname[32], error[32]
    
    
get_cvar_string("amx_sql_host"host64)
    
get_cvar_string("amx_sql_user"username32)
    
get_cvar_string("amx_sql_pass"password32)
    
get_cvar_string("amx_sql_db"dbname32)
    
    
dbc dbi_connect(hostusernamepassworddbnameerror32)
    
    if (
dbc SQL_OK)
        
client_print(1print_chat"[AMXX] SQL Connection Failed ")
}

public 
clcmd_fullupdate() {
    return 
PLUGIN_HANDLED_MAIN
}
 
public 
event_restart_attempt() {
    new 
players[32], num
    get_players
(playersnum"a")
    for (new 
inum; ++i)
        
g_restart_attempt[players[i]] = true
}
 
public 
event_hud_reset(id) {
    if (
g_restart_attempt[id]) {
        
g_restart_attempt[id] = false
        
return
    }
    
event_player_spawn(id)
}

public 
client_putinserver(id) {
    new 
steamid[35]
    
get_user_authid(idsteamid34)
   
    new 
sql[255]
    
format(sql,254,"SELECT * FROM amx_csn_users WHERE steam_id = '%s'"steamid)
    
    new 
Result:res dbi_query(dbcsql)
     
    if(!
res)
    {
        
client_print(1print_chat"[AMXX] Blad bazy danych")
    }
    
    while(
dbi_nextrow(Result))
            {
            
plr_points[id] = dbi_result(Result,"points")
        }
    
    
client_print(1print_chat"[AMXX] Na serwer wlazl ktoz ze steamid %s, ma id (%i) oraz %s2 bonusowych punktow"steamididplr_points[id])
}
 
// this function is called on player spawn
public event_player_spawn(id) {
    new 
BONUSKASA id*100
    cs_set_user_money
(idcs_get_user_money(id) + BONUSKASA)
    
client_print(1print_chat"[AMXX] SPAWN: NOWA RUNDA | Jestes zajebisty i dostajesz $%d"BONUSKASA)



YamiKaitou 10-14-2007 22:45

Re: Problem with SQL...
 
Not based on your problem, but when using client_print, try using id in the first arg. Cause, you can't be sure that the user at index 1 is always the person using the command/function.


Now, your problem. You are storing the db result to the variable named res. Why are you using Result in the params for dbi_nextrow/dbi_result?

AceDude 10-15-2007 12:16

Re: Problem with SQL...
 
1) It is for testing, so its ok. :)

2) It is here after my last try. It works same is its 'res'...

Any other ideas?

AceDude 10-15-2007 12:29

Re: Problem with SQL...
 
Ok, as I thought, script is 100% OK, but... i has set wrong db in sql.cfg... rawr...

Podunk 10-15-2007 17:00

Re: Problem with SQL...
 
lols he said rawr


All times are GMT -4. The time now is 01:21.

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