AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Create multiple SQL Tables (https://forums.alliedmods.net/showthread.php?t=332302)

lexzor 05-04-2021 12:02

Create multiple SQL Tables
 
Hello. Can i create multiple tables like this:
PHP Code:

new const g_szTables[][] =
{
    
"Online_Players"// Tabelul pentru playerii online
    
"Server_Informations" // Tabelul pentru informatiile serverului
    // Tabelul pentru admini si flaguri
}

new const 
g_szTablesInfo[][] = 
{
    
" ( `id` INT(11) NOT NULL , `name` VARCHAR(33) NOT NULL , `ip` VARCHAR(33) NOT NULL , `steamid` VARCHAR(33) NOT NULL , `frags` INT(33) NOT NULL , `deaths` INT(33) NOT NULL , PRIMARY KEY (`id`))",
    
" ( `hostname` VARCHAR(255) NOT NULL , `ipaddress` VARCHAR(255) NOT NULL , `onlineplayers` INT(3) NOT NULL , `onlineadmins` INT(3) NOT NULL , `actualmap` VARCHAR(255) NOT NULL , `nextmap` VARCHAR(255) NOT NULL , PRIMARY KEY (`hostname`))"    
}

public 
MySql_Init()
{
    
g_SqlTuple SQL_MakeDbTuple(g_szPanelInfo[MYSQL_HOST], g_szPanelInfo[MYSQL_USER],g_szPanelInfo[MYSQL_PASS], g_szPanelInfo[MYSQL_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
    
new szCache[1024]
    
    for(new 
0sizeof(g_szTables); i++)
    {
        
formatex(szCachecharsmax(szCache), "CREATE TABLE IF NOT EXISTS %s %s"g_szTables[i], g_szTablesInfo[i])
        
server_print(szCache)        

        
Queries SQL_PrepareQuery(SqlConnectionszCache)
        
        if(!
SQL_Execute(Queries))
        {
            
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
            
set_fail_state(g_Error)     
        }
            
    }
        
    
SQL_FreeHandle(Queries)
    
    
SQL_FreeHandle(SqlConnection)   


Because i got errors.

Code:

CREATE TABLE IF NOT EXISTS Online_Players
CREATE TABLE IF NOT EXISTS Online_Playe ( `id` INT(11) NOT NULL , `name` VARCHAR(33) NOT NULL , `ip` VARCHAR(33) NOT NULL , `steamid` VARCHAR(33) NOT NULL , `frags` INT(33) NOT NULL , `deaths` INT(33) NOT NULL , PRIMARY KEY (`id`))

L 05/04/2021 - 18:59:41: [AMXX] Plugin ("panel.amxx") is setting itself as failed.
L 05/04/2021 - 18:59:41: [AMXX] Plugin says: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ( `id` INT(11) NOT NULL , `name` VARCHAR(33) NOT NULL , `ip` VARCHAR(33) N...' at line 1

first 2 rows are debugging
PHP Code:

server_print(szTemp)
server_print(szSecondTemp


lexzor 05-04-2021 12:45

Re: Create multiple SQL Tables
 
is working now. Code:

PHP Code:

for(new 0sizeof(g_szTables); i++)
    {
        
formatex(szCachecharsmax(szCache), "CREATE TABLE IF NOT EXISTS %s %s"g_szTables[i], g_szTablesInfo[i])
        
server_print(szCache)        

        
Queries SQL_PrepareQuery(SqlConnectionszCache)
        
        if(!
SQL_Execute(Queries))
        {
            
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
            
set_fail_state(g_Error)     
        }        
    } 



All times are GMT -4. The time now is 02:29.

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