Raised This Month: $ Target: $400
 0% 

Solved Create multiple SQL Tables


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-04-2021 , 12:02   Create multiple SQL Tables
Reply With Quote #1

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

Last edited by lexzor; 05-04-2021 at 15:47.
lexzor is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-04-2021 , 12:45   Re: Create multiple SQL Tables
Reply With Quote #2

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)     
        }        
    } 
lexzor is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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