AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to make copy of a mysql table to a config file (ini) (https://forums.alliedmods.net/showthread.php?t=313228)

xJaw 01-01-2019 09:26

How to make copy of a mysql table to a config file (ini)
 
I was trying to make copy of my db table but was not getting how can i loop through each row in the table and save that to my file can anyone show just this part of iterating through each row and getting values from there ??

For example : table name = EXAMPLE

EXAMPLE
--------------------
Name SteamId
xyz STEAM: xxxx
abc STEAM: xxxx

Bugsy 01-01-2019 11:48

Re: How to make copy of a mysql table to a config file (ini)
 
PHP Code:


SELECT 
FROM myTable ORDER BY OneOfTheFields

while ( SQL_MoreResultsquery ) )
{
   
SQL_ReadResultquery )
   
SQL_ReadResultquery )
   
//repeat for number of columns

   
Format output line "%s %s %s %s %s" Field1 Field2 Field3 Field4 Field5
   write to file the formatted line

   SQL_NextRow
query )



xJaw 01-02-2019 00:13

Re: How to make copy of a mysql table to a config file (ini)
 
Hello bugsy thanks for the info but i did exactly like this and read this tutorial too https://forums.alliedmods.net/showthread.php?t=132686

Here is my code and is still not working :(

PHP Code:

#include <amxmodx>
#include <sqlx>

new Host[]     = "localhost"
new User[]    = "root"
new Pass[]     = ""
new Db[]     = "sqltest"

new Handle:g_SqlTuple
new g_Error[512]


public 
plugin_init() {
    
register_plugin("PLUGIN""VERSION""AUTHOR")

    
set_task(1.5"Load_MySql")
}

public 
plugin_end()
    
SQL_FreeHandle(g_SqlTuple)

public 
Load_MySql()
{
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
    new 
errorCode
    
new Handle:sql SQL_Connect(g_SqlTupleerrorCodeg_Errorcharsmax(g_Error))

    new 
Handle:query
    
    
new foundEXP[10], foundSteam[33]

    
query SQL_PrepareQuery(sql,"SELECT * FROM `tutorial` ORDER BY `exp`")

    
server_print("STAGE 2")
    while(
SQL_MoreResults(query))
    {
        
server_print("STAGE 3")
        
SQL_ReadResult(query0foundSteamcharsmax(foundSteam))
        
SQL_ReadResult(query1foundEXPcharsmax(foundEXP))

        
server_print("%s EXP = %d"foundSteamstr_to_num(foundEXP)) // Just to view it in server console
        
SQL_NextRow(query)
    }


It never outputs STAGE 3 ..


Edit:
I even added this after the preparation of my query
PHP Code:

 server_print("Results %d"SQL_NumResults(query)) 

And it outputs "Results 0"

Even my Table has 2 Enteries in it :(

klippy 01-02-2019 03:40

Re: How to make copy of a mysql table to a config file (ini)
 
Read the tutorial again, you are missing steps. You didn't execute the query at all.


All times are GMT -4. The time now is 07:35.

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