SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 28/06/2020, 09:25 PM   #1
xAlecsu
Big Clucker
 
Join Date: Aug 2013
Posts: 189
Reputation: 2
Default update mysql loadfaction

Hello , i have this code :
PHP Code:
stock LoadFactions()
{
    new 
query[400];
    for(new 
idid MAX_FACTIONSid++) // Goes through all the slots, looking for the data
    
{
        
format(querysizeof(query), "SELECT * FROM Factions WHERE ID = %d"id); // Selects all the information from the table
        
mysql_query(MySQL:Databasequery);
        
mysql_store_result();

        if(
cache_num_rows())
        if(
mysql_fetch_row_format(query,"|"))
        {
            
sscanf(query"p<|>e<is[64]ds[32]s[32]s[32]s[32]s[32]>",Factions[id]); // SSCANF seperates the data into the variables
            
Total_Factions_Created++; // Counts the factions created
        
}

    }
    
printf("> %d factions have been loaded from the database."Total_Factions_Created); // Prints out the information of how many factions created
    
return 1;

and i get error from
error 017: undefined symbol "mysql_fetch_row_format"
error 017: undefined symbol "mysql_store_result"

what become mysql_fetch_row_format and mysql_store_result in mysql r41-4?
xAlecsu is offline   Reply With Quote
Old 28/06/2020, 09:33 PM   #2
SkyFlare
Huge Clucker
 
SkyFlare's Avatar
 
Join Date: Apr 2015
Location: NZ
Posts: 221
Reputation: 43
Default Re: update mysql loadfaction

Quote:
Originally Posted by xAlecsu View Post
Hello , i have this code :
PHP Code:
stock LoadFactions()
{
    new 
query[400];
    for(new 
idid MAX_FACTIONSid++) // Goes through all the slots, looking for the data
    
{
        
format(querysizeof(query), "SELECT * FROM Factions WHERE ID = %d"id); // Selects all the information from the table
        
mysql_query(MySQL:Databasequery);
        
mysql_store_result();

        if(
cache_num_rows())
        if(
mysql_fetch_row_format(query,"|"))
        {
            
sscanf(query"p<|>e<is[64]ds[32]s[32]s[32]s[32]s[32]>",Factions[id]); // SSCANF seperates the data into the variables
            
Total_Factions_Created++; // Counts the factions created
        
}

    }
    
printf("> %d factions have been loaded from the database."Total_Factions_Created); // Prints out the information of how many factions created
    
return 1;

and i get error from
error 017: undefined symbol "mysql_fetch_row_format"
error 017: undefined symbol "mysql_store_result"

what become mysql_fetch_row_format and mysql_store_result in mysql r41-4?
Here's how I am loading my Factions, it's a little bit different and caches each row individually with its results.

PHP Code:
LoadFactions()
{
    new 
rows;
    
mysql_query(g_SQL"SELECT * FROM `factions` ORDER BY `id` ASC");
    if(
cache_get_row_count(rows))
    {
        for(new 
0rows && MAX_FACTIONSr++)
        {
               
cache_get_value_name_int(r"id"Factions[r][ID]);//Int Catching
            
cache_get_value_name(r"factionname"Factions[r][FactionName],72);//Text Caching
            
cache_get_value_name_float(r"hqx"Factions[r][FacHQX]);//Float Caching
            //These get stored into the Enumerator for the specified ID which is 'r'.
        
}
    }
    
printf("%i Faction Slot(s) loaded from the Database!"rows);//Rows will count the factions created based on how many rows were available in the MySQL Database
    
return 1;

See that g_SQL in my query? that's a handle, make sure you're using a handle for MySQL, at the top of your script.
PHP Code:
// MySQL connection handle
new MySQLg_SQL
By the way you shouldn't use Stock before your functions if that piece of code is inside your Gamemode Script.
__________________
Purchasable Scripting Services Available, Inbox me with your Requests.
My Project Progress Tracker
My Work
Link
Information
S-Store System V2 LinkIngame Store in Dialogs
SkyFlare is offline   Reply With Quote
Old 28/06/2020, 10:29 PM   #3
xAlecsu
Big Clucker
 
Join Date: Aug 2013
Posts: 189
Reputation: 2
Default Re: update mysql loadfaction

he said ,i have 0 faction loaded ,but i havee 9 factions in database..
xAlecsu is offline   Reply With Quote
Old 28/06/2020, 10:42 PM   #4
SkyFlare
Huge Clucker
 
SkyFlare's Avatar
 
Join Date: Apr 2015
Location: NZ
Posts: 221
Reputation: 43
Default Re: update mysql loadfaction

Quote:
Originally Posted by xAlecsu View Post
he said ,i have 0 faction loaded ,but i havee 9 factions in database..
thats because in the query I showed.
PHP Code:
mysql_query(g_SQL"SELECT * FROM `factions` ORDER BY `id` ASC"); 
its set for my Database layout specifically.

you will need to adjust it for your database column's, I dont know if you have an "id" column in your Factions Database, so if you don't then that will be why, also check your MySQL Logs File in your Server Folder, you will find out why it's not working correctly.

I know for starters, your "Factions" table is capitalized, where mine isn't.

so
Code:
SELECT * FROM `Factions`
will need to be your usage there.
ORDER BY `id` ASC" means we are ordering each faction ascending from the lowest "id" in Factions Table.
meaning if you dont have an "id" column in "Factions" table, you wont load any rows.

but you do, again it's capitalized (it doesn't seem logical right now but it changes a lot of things, so set the capitalization, make sure its correct)

PHP Code:
mysql_query(g_SQL"SELECT * FROM `Factions` ORDER BY `ID` ASC"); 
__________________
Purchasable Scripting Services Available, Inbox me with your Requests.
My Project Progress Tracker
My Work
Link
Information
S-Store System V2 LinkIngame Store in Dialogs
SkyFlare is offline   Reply With Quote
Old 29/06/2020, 12:36 PM   #5
xAlecsu
Big Clucker
 
Join Date: Aug 2013
Posts: 189
Reputation: 2
Default Re: update mysql loadfaction

PHP Code:
LoadFactions()
{
    new 
rows;
    
mysql_query(Database"SELECT * FROM `factions` ORDER BY `ID` ASC"); 
    if(
cache_get_row_count(rows))
    {
        for(new 
0rows && Total_Factions_Createdr++)
        {
            
cache_get_value_name_int(r"ID"Factions[r][ID]);//Int Catching
            
cache_get_value_name(r"FactionName"Factions[r][FactionName],32);//Text Caching
            //These get stored into the Enumerator for the specified ID which is 'r'.
        
}
    }
    
printf("%i Faction Slot(s) loaded from the Database!"rows);//Rows will count the factions created based on how many rows were available in the MySQL Database
    
return 1;

Still don't work...
Same "0 factions loaded" ,but i have factions on database.
xAlecsu is offline   Reply With Quote
Old 29/06/2020, 12:58 PM   #6
Macronix
Huge Clucker
 
Macronix's Avatar
 
Join Date: Jul 2010
Location: Germany
Posts: 478
Reputation: 100
Default Re: update mysql loadfaction

Try this:

pawn Code:
LoadFactions()
{
    mysql_query(Database, "SELECT * FROM factions");

    new rows = cache_num_rows();

    if(rows > 0)
    {
        for (new i = 0; i < rows; i++)
        {
            cache_get_value_int(i, "ID", Factions[i][ID]);
            cache_get_value(i, "FactionName", Factions[i][FactionName]);
        }
    }
   
    printf("%i Factions loaded!", rows);
    return 1;
}
Macronix is offline   Reply With Quote
Old 29/06/2020, 03:14 PM   #7
xAlecsu
Big Clucker
 
Join Date: Aug 2013
Posts: 189
Reputation: 2
Default Re: update mysql loadfaction

same...
PHP Code:
LoadFactions()
{
    
mysql_query(Database"SELECT * FROM factions");

    new 
rows cache_num_rows();

    if(
rows 0)
    {
        for (new 
0rowsi++)
        {
            
cache_get_value_int(i"FID"fInfo[i][FID]);
            
cache_get_value(i"FactionName"fInfo[i][FactionName]);
            
cache_get_value_int(i"Members"fInfo[i][Members]);
        }
    }
    
    
printf("%i Factions loaded!"rows);
    return 
1;

mysql data print: https://imgur.com/EwLsvUn.png

to onplayerdisconnect i added:
PHP Code:
    mysql_format(DatabaseQuerysizeof(DB_Query), "UPDATE `factions` SET `FactionName` = %s WHERE `ID` = %d LIMIT 1",
    
fInfo[Total_Factions_Created][FactionName], fInfo[Total_Factions_Created][FID]);
    
mysql_tquery(DatabaseQuery); 
for save when i make restart to server
xAlecsu is offline   Reply With Quote
Old 29/06/2020, 03:27 PM   #8
Macronix
Huge Clucker
 
Macronix's Avatar
 
Join Date: Jul 2010
Location: Germany
Posts: 478
Reputation: 100
Default Re: update mysql loadfaction

What is the mysql.log showing? And why are you looking for "ID" (WHERE clause) in your query when it's "FID" in the Database structure?
How do you establish the connection to MySQL?
Macronix is offline   Reply With Quote
Old 29/06/2020, 03:35 PM   #9
xAlecsu
Big Clucker
 
Join Date: Aug 2013
Posts: 189
Reputation: 2
Default Re: update mysql loadfaction

oh ,i changed to "FID"
and i try this:
PHP Code:
stock LoadFactions()
{
    new 
Query[256];
    
mysql_format(DatabaseQuerysizeof(Query), "SELECT * FROM `factions` WHERE `FID` = '%d', 'FactionName' = '%s', 'Members' = '%d' LIMIT 1"fInfo[Total_Factions_Created][FID],fInfo[Total_Factions_Created][FactionName],fInfo[Total_Factions_Created][Members]);
    
mysql_query(MySQL:Database,Query);

    new 
rows cache_num_rows();

    if(
rows 0)
    {
        for (new 
0rowsi++)
        {
            
cache_get_value_int(i"FID"fInfo[i][FID]);
            
cache_get_value(i"FactionName"fInfo[i][FactionName]);
            
cache_get_value_int(i"Members"fInfo[i][Members]);
        }
    }
    
    
printf("%i Factions loaded!"rows);
    return 
1;

and ongamemodeinit
PHP Code:
LoadFactions(); 
And still don't work..
And mysql_log it's blank. I started my server from 10 times and it's still blank this folder.

EDIT:
ongamemodeinit its:
PHP Code:
public OnGameModeInit()
{
    
SetGameModeText("Bare Script");
    
AddPlayerClass(265,1958.3783,1343.1572,15.3746,270.1425,0,0,0,0,-1,-1);
    
ShowPlayerMarkers(0);
    
DisableInteriorEnterExits();
    
UsePlayerPedAnims();
    
ShowNameTags(1);
    
LoadFactions();
    new 
MySQLOptoption_id mysql_init_options();
    
mysql_set_option(option_idAUTO_RECONNECTtrue); 

    
Database mysql_connect(MYSQL_HOSTMYSQL_USERMYSQL_PASSMYSQL_DATABASEoption_id); 

    if(
Database == MYSQL_INVALID_HANDLE || mysql_errno(Database) != 0
    {
        print(
"Nu sa putut face conexiunea cu MySQL.\nGamemode-ul se va inchide."); 

        
SendRconCommand("exit"); 
        return 
1;
    }

    print(
"Conexiunea cu MySQL sa realizat cu succes."); 
    
mysql_tquery(Database"CREATE TABLE IF NOT EXISTS `PLAYERS` (`ID` int(11) NOT NULL AUTO_INCREMENT,`USERNAME` varchar(24) NOT NULL,`PASSWORD` char(65) NOT NULL,`SALT` char(11) NOT NULL,`SCORE` mediumint(7), `KILLS` mediumint(7), `CASH` mediumint(7) NOT NULL DEFAULT '0',`DEATHS` mediumint(7) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), UNIQUE KEY `USERNAME` (`USERNAME`))");
    return 
1;

xAlecsu is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[HELP] MySQL Update ZED15 Scripting Help 2 18/02/2017 07:10 PM
MySQL Update Banditul18 Scripting Help 2 10/11/2016 05:39 PM
Update Mysql Stop Scripting Help 1 27/09/2016 04:52 PM
mysql update. audriuxxx Scripting Help 2 25/06/2013 03:24 PM
Faction type and slot resetting after LoadFaction is called. [rep++] seanny Scripting Help 0 16/04/2012 11:17 AM


All times are GMT. The time now is 02:39 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.