Advertisement
Guest User

Untitled

a guest
Apr 27th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.38 KB | None | 0 0
  1. Code:
  2.  
  3. public MySql_Init()
  4. {
  5.     // we tell the API that this is the information we want to connect to,
  6.     // just not yet. basically it's like storing it in global variables
  7.     g_SqlTuple = SQL_MakeDbTuple(Host,Userz,Pass,Db)
  8.    
  9.     // ok, we're ready to connect
  10.     new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
  11.     if(SqlConnection == Empty_Handle)
  12.         // stop the plugin with an error message
  13.         set_fail_state(g_Error)
  14.        
  15.     new Handle:Queries
  16.     // we must now prepare some random queries
  17.     Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS tutorial (steamid varchar(32),exp INT(11))")
  18.  
  19.     if(!SQL_Execute(Queries))
  20.     {
  21.         // if there were any problems the plugin will set itself to bad load.
  22.         SQL_QueryError(Queries,g_Error,charsmax(g_Error))
  23.         set_fail_state(g_Error)
  24.        
  25.     }
  26.    
  27.     // Free the querie
  28.     SQL_FreeHandle(Queries)
  29.    
  30.     // you free everything with SQL_FreeHandle
  31.     SQL_FreeHandle(SqlConnection)  
  32. }  
  33.  
  34. //public plugin_end()
  35. //{
  36.     // free the tuple - note that this does not close the connection,
  37.     // since it wasn't connected in the first place
  38.    // SQL_FreeHandle(g_SqlTuple)
  39. //}
  40.  
  41. public Load_MySql(id)
  42. {
  43.     new szName[32], szTemp[512]
  44.     get_user_name(id, szName, charsmax(szName))
  45.    
  46.     new Data[1]
  47.     Data[0] = id
  48.    
  49.     //we will now select from the table `tutorial` where the steamid match
  50.     format(szTemp,charsmax(szTemp),"SELECT * FROM `zmescape` WHERE (`escapes`.`name` = '%s')", szName)
  51.     SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
  52. }
  53.  
  54. public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
  55. {
  56.     if(FailState == TQUERY_CONNECT_FAILED)
  57.     {
  58.         log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
  59.     }
  60.     else if(FailState == TQUERY_QUERY_FAILED)
  61.     {
  62.         log_amx("Load Query failed. [%d] %s", Errcode, Error)
  63.     }
  64.  
  65.     new id
  66.     id = Data[0]
  67.    
  68.     if(SQL_NumResults(Query) < 1)
  69.     {
  70.         //.if there are no results found
  71.        
  72.         new szName[32]
  73.         get_user_name(id, szName, charsmax(szName)) // get user's steamid
  74.        
  75.         //  if its still pending we can't do anything with it
  76.         if (equal(szName,"ID_PENDING"))
  77.             return PLUGIN_HANDLED
  78.            
  79.         new szTemp[512]
  80.        
  81.         // now we will insturt the values into our table.
  82.         format(szTemp,charsmax(szTemp),"INSERT INTO `zmescape` ( `name` , `escapes`)VALUES ('%s','0');",szName)
  83.         SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
  84.     }
  85.     else
  86.     {
  87.         // if there are results found
  88.         escapes[id]         = SQL_ReadResult(Query, 1)
  89.     }
  90.    
  91.     return PLUGIN_HANDLED
  92. }  
  93.  
  94. public Save_MySql(id)
  95. {
  96.     new szName[32], szTemp[512]
  97.     get_user_name(id, szName, charsmax(szName))
  98.    
  99.     // Here we will update the user hes information in the database where the steamid matches.
  100.     format(szTemp,charsmax(szTemp),"UPDATE `zmescape` SET `escapes` = '%i' WHERE `escapes`.`name` = '%s';",escapes[id], szName)
  101.     SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
  102. }  
  103.  
  104. As you see plugin_end function is quoted because it gives me error : [MySQL] Invalid handle: 0
  105.  
  106. The variable: [B]escapes[/B] just does not saves.. I haven't got any errors from the plugin.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement