AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   MySQL helps (https://forums.alliedmods.net/showthread.php?t=174037)

Darkskypew 12-14-2011 11:11

MySQL helps
 
Hello all

Help with errors please...

PHP Code:

L 12/13/2011 19:48:33: [MySQLInvalid info tuple handle0
L 12
/13/2011 19:48:33: [AMXXDisplaying debug trace (plugin "zp50_rewards_ammopacks.amxx")
L 12/13/2011 19:48:33: [AMXXRun time error 10native error (native "SQL_ThreadQuery")
L 12/13/2011 19:48:33: [AMXX]    [0zp50_rewards_ammopacks.sma::Load_MySql (line 188)
L 12/13/2011 19:48:33: [AMXX]    [1zp50_rewards_ammopacks.sma::client_connect (line 255

Code create:
PHP Code:

public MySql_Init()
{
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
   
    new 
ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_Error)
       
    new 
Handle:Queries
    Queries 
SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS zl_stats (Nick varchar(32),AP INT(11),Level INT(11),Damage INT(11),DamageMAX INT(11))")

    if(!
SQL_Execute(Queries))
    {
        
// if there were any problems
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        
set_fail_state(g_Error)
    }
    
    
// close the handle
    
SQL_FreeHandle(Queries)
   
    
// you free everything with SQL_FreeHandle
    
SQL_FreeHandle(SqlConnection)   


Code register:
PHP Code:

public register_client(FailState,Handle:Query,Error[],Errcode,Data[], sizeFloat:queuetime)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)
    }
    new 
id
    id 
Data[0]
    if(!
is_user_connected(id)) return PLUGIN_HANDLED
    
    
if(SQL_NumResults(Query) < 1
    {
        
//.if there are no results found
        
    
get_user_name(id,name,31)
            
    new 
szTemp[512]
    
APStart zp_ammopacks_get(id)
        
        
// now we will insturt the values into our table.
    
formatex(szTemp350"INSERT INTO `zl_stats` \
    (`Nick`, `AP`, `Level`, `Damage`, `DamageMAX`) \
    values ('%s', '%d', '%d', '%d', '%d')"
,
    
//values (^"%s^", ^"%d^", ^"%d^", ^"%d^", ^"%d^")",
    
nameAPStartLevel[id], g_DamageEXP[id], MaxEXP[id])
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    } 
    else
    if(
SQL_MoreResults(Query))
    {
        
//zp_ammopacks_get(id)
        
APS SQL_ReadResult(Handle:QuerySQL_FieldNameToNum(Query"AP"));
        
Level[id] = SQL_ReadResult(Handle:Query1)
        
g_DamageEXP[id] = SQL_ReadResult(Handle:Query2)
        
MaxEXP[id] = SQL_ReadResult(Handle:Query3)
    }
    return 
PLUGIN_HANDLED


Code load:
PHP Code:

public Load_MySql(id)
{
    new 
szTemp[512]
    new 
name[33]
    
get_user_name(id,name,31)
    new 
Data[1]
    
Data[0] = id
    formatex
(szTemp180"SELECT \
    `AP` , `Level` , `Damage` , `DamageMAX` \
    FROM `zl_stats` WHERE `Nick` = '%s'"
,
    
name)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)


Code save:
PHP Code:

public Save_MySql(id)
{
    new 
szTemp[512]
    
get_user_name(id,name,31)
    
APStart zp_ammopacks_get(id)
    
// Here we will update the user hes information in the database where the steamid matches.
    
format(szTemp,charsmax(szTemp),"UPDATE `zl_stats` \
    SET `AP` = '%d', `Level` = '%d', `Damage` = '%d', `DamageMAX` = '%d' \
    WHERE `zl_stats`.`Nick` = '%s';"
,
    
zp_ammopacks_get(id), Level[id], g_DamageEXP[id], MaxEXP[id], name)
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)


Help please, the floor of the week to solve a problem I can not: (


All times are GMT -4. The time now is 11:52.

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