AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Connection to database and another thing. (https://forums.alliedmods.net/showthread.php?t=229157)

Jhob94 11-02-2013 12:31

Connection to database and another thing.
 
Hi, i took this from admin.sma and edited for work in amxbans.

PHP Code:

AddVIP(id)
{
    new 
error[128], errno

    
new Handle:info SQL_MakeStdTuple()
    new 
Handle:sql SQL_Connect(infoerrnoerror127)
    
    if (
sql == Empty_Handle)
    {
        
server_print("[AMXX] %L"LANG_SERVER"SQL_CANT_CON"error)
    }
    
    new 
table[32]
    
    
get_cvar_string("amx_sql_table"table31)
    
    new 
Handle:query SQL_PrepareQuery(sql"SELECT * FROM `%s` WHERE (`auth` = '%s')"tableauth)

    if (!
SQL_Execute(query))
    {
        
SQL_QueryError(queryerror127)
        
server_print("[AMXX] %L"LANG_SERVER"SQL_CANT_LOAD_ADMINS"error)
        
console_print(id"[AMXX] %L"LANG_SERVER"SQL_CANT_LOAD_ADMINS"error)
    }
    
    else if (
SQL_NumResults(query))
    {
        
// up amount of days, need work on it later
        
console_print(id"[%s] %s already exists!"PLUGINNAMEauth)
    }
    
    else
    {
        
//adding
        
console_print(id"Adding to database:^n^"%s^" ^"%s^" ^"%s^""authflags)
    
        new 
id_what_valuecreated_what_valueexpired_what_value10days_seconds
        id_what_value 
= ?
        
created_what_value = ?
        
10days_seconds = (10 24 60 60)
        
expired_what_value created_what_value 10days_seconds
        SQL_QueryAndIgnore
(sql"REPLACE INTO `%s` (`id`, `username`, `password`, `access, `flags`, `steamid`, `nickname`, `ashow`, `created`, `expired`, `days`) VALUES ('%s', '%s', '', 't', 'ce', '%s', '%s', '1', '%s', '%s', '10')"tableid_what_valuenameauthnamecreated_what_valueexpired_what_value)
    }
    
    
SQL_FreeHandle(query)
    
SQL_FreeHandle(sql)
    
SQL_FreeHandle(info)


But there is 2 things that i dont know.
How to set the correct id?
What value i put in created date?


About created date, the value is all seconds from 1 January 1970 till the moment of being created.
Bah i have no idea how to find that value.

Also, in the case of steam id already in database, how to edit time of admin?

Last: Is this a good method for connect into database or should i use dbi instead?


All times are GMT -4. The time now is 23:16.

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