Raised This Month: $12 Target: $400
 3% 

MYSQL - table is not created


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BlacKisEverywhere
Junior Member
Join Date: Feb 2020
Old 02-08-2020 , 06:49   MYSQL - table is not created
Reply With Quote #1

Hi. I tried to make test vip plugin but i finished on creating table and save players to thar table.
PHP Code:
#include <sourcemod>

ConVar g_tableName;
Database g_db;

public 
Plugin info = {
    
name "Test Vip",
    
author "BlacK",
    
description "Test VIP"
}

public 
void OnPluginStart(){
    
g_tableName CreateConVar("nazwa_tabeli""tVip""Ustawia nazwę tabeli w bazie danych");

    
Database.Connect(OnConnect"tVip");
    
PrintToServer("[Onecer] Test vip aktywny");
}

public 
void OnConnect(Database dbchar[] errorany data){
    
char tableName[20];
    
g_tableName.GetString(tableNamesizeof(tableName));

    if(
db == null){
        
PrintToServer("[Onecer] Nie można połączyć się z bazą danych.");
        
SetFailState("[Onecer] Nie można połączyć się z bazą danych.");
        
PrintToConsoleAll("[Onecer] Nie można połączyć z bazą danych");
        return;
    }
    
    
PrintToServer("[Onecer] Połączono z bazą danych");
    
PrintToConsoleAll("[Onecer] Połączono z bazą danych");

    
g_db db;

    
char query[264];
    
g_db.Format(querysizeof(query), "CREATE TABLE IF NOT EXISTS `%s` (`name` varchar(30) NOT NULL, `steamId` varchar(32), `enabled` int(1))"tableName);
    
g_db.Query(ConnectCallbackquery);
}

public 
void ConnectCallback(Database dbDBResultSet resultschar[] errorany data){
    
char tableName[20];
    
g_tableName.GetString(tableNamesizeof(tableName));
    
PrintToConsoleAll("--------- Connect Callback ---------");
    if(
results == null){
        
PrintToServer("[Onecer] Nie można Stworzyć/Wczytać tabeli");
        
PrintToConsoleAll("[Onecer] Nie można Stworzyć/Wczytać tabeli");
        return;
    }

    
PrintToServer("[Onecer] Stworzono/Wczytano tabelę");
    
PrintToConsoleAll("[Onecer] Stworzono/Wczytano tabelę");

    for(
int i 1<= MaxClientsi++){
        if(
IsClientInGame(i)){
            
char steamId[32];
            
GetClientAuthId(iAuthId_Steam2steamIdsizeof(steamId));

            
char name[30];
            
GetClientName(inamesizeof(name));

            
int enabled 1;

            
InsertPlayer(namesteamIdenabled);
        }
    }
}
public 
void InsertPlayer(char[] namechar[] steamIdint enabled){
    
char tableName[20];
    
g_tableName.GetString(tableNamesizeof(tableName));

    
char query[264];
    
g_db.Format(querysizeof(query), 
        
"INSERT INTO `%s` (`name`, `steamId`, `enabled`) SELECT * FROM (SELECT '%s', '%s', '%d') AS tmp WHERE NOT EXISTS (SELECT `steamId` FROM `%s` WHERE `steamId` = '%s') LIMIT 1;",
        
tableNamenamesteamIdenabledtableNamesteamId
    
);
    
g_db.Query(InsertCallbackquery);
}

public 
void InsertCallback(Database dbDBResultSet resultschar[] errorany data){
    
PrintToServer("[Results]: %s"results)
    if(
results == null){
        
PrintToServer("[Onecer] Nie można wczytać klienta");
        
PrintToConsoleAll("[Onecer] Nie można wczytać klienta");
    }

- I didn't get any logs in console.
- I pasted create table query to phpmyadmin console and it created a table.

Thanks for all help.
BlacKisEverywhere is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 02-24-2020 , 18:29   Re: MYSQL - table is not created
Reply With Quote #2

Because you pass ConVar instead of string in your first query.

Use:
Code:
char sTable[32];
tableName.GetString(sTable, sizeof sTable);
and pass sTable there.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 02-24-2020 at 18:29.
Dragokas is offline
Reply


Thread Tools
Display Modes

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 10:43.


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