SA-MP Forums Archive
Which one is better? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Which one is better? (/showthread.php?tid=637674)



Which one is better? - DuyDang2412 - 19.07.2017

Hello guys, I have two ways to update the database:

1.
PHP код:
SaveBusiness(businessid)
{
    new 
query[210];
    
mysql_format(MHandlequerysizeof(query), "UPDATE `businesses` SET `OwnerName` = '%s', \
    `Name` = '%s', \
    `Type` = %d, \
    `Price` = %d WHERE `SQLID` = %d"
,
    
Business[businessid][bOwnerName],
    
Business[businessid][bName],
    
Business[businessid][bType],
    
Business[businessid][bPrice],
    
Business[businessid][bSQLID]);
    
mysql_query(MHandlequery);
    
mysql_format(MHandlequerysizeof(query), "UPDATE `businesses` SET `Stock` = %d, \
    `Balance` = %d, \
    `ExteriorX` = %.4f, \
    `ExteriorY` = %.4f, \
    `ExteriorZ` = %.4f, \
    `ExteriorVW` = %d WHERE `SQLID` = %d"
,
    
Business[businessid][bStock],
    
Business[businessid][bBalance],
    
Business[businessid][bExteriorX],
    
Business[businessid][bExteriorY],
    
Business[businessid][bExteriorZ],
    
Business[businessid][bExteriorVW],
    
Business[businessid][bSQLID]);
    
mysql_query(MHandlequery);
    
mysql_format(MHandlequerysizeof(query), "UPDATE `businesses` SET `InteriorX` = %.4f, \
    `InteriorY` = %.4f, \
    `InteriorZ` = %.4f, \
    `InteriorID` = %d, \
    `InteriorVW` = %d WHERE `SQLID` = %d"
,
    
Business[businessid][bInteriorX],
    
Business[businessid][bInteriorY],
    
Business[businessid][bInteriorZ],
    
Business[businessid][bInteriorID],
    
Business[businessid][bInteriorVW],
    
Business[businessid][bSQLID]);
    
mysql_query(MHandlequery);
    return 
1;

_____________________________________________
2.
PHP код:
SaveBusiness(businessid)
{
    new 
query[2048];
    
mysql_format(MHandlequerysizeof(query), "UPDATE `businesses` SET `OwnerName` = '%s', \
    `Name` = '%s', \
    `Type` = %d, \
    `Price` = %d, \
    `Stock` = %d, \
    `Balance` = %d, \
    `ExteriorX` = %.4f, \
    `ExteriorY` = %.4f, \
    `ExteriorZ` = %.4f, \
    `ExteriorVW` = %d, \
    `InteriorX` = %.4f, \
    `InteriorY` = %.4f, \
    `InteriorZ` = %.4f, \
    `InteriorID` = %d, \
    `InteriorVW` = %d WHERE `SQLID` = %d"
,
    
Business[businessid][bOwnerName],
    
Business[businessid][bName],
    
Business[businessid][bType],
    
Business[businessid][bPrice],
    
Business[businessid][bStock],
    
Business[businessid][bBalance],
    
Business[businessid][bExteriorX],
    
Business[businessid][bExteriorY],
    
Business[businessid][bExteriorZ],
    
Business[businessid][bExteriorVW],
    
Business[businessid][bInteriorX],
    
Business[businessid][bInteriorY],
    
Business[businessid][bInteriorZ],
    
Business[businessid][bInteriorID],
    
Business[businessid][bInteriorVW],
    
Business[businessid][bSQLID]);
    
mysql_query(MHandlequery);
    return 
1;

I don't know which one is better for a roleplay server. The number one will be slower than the second but the second will use too much memory because it has the variable 'query' with 2048 sizes.
Thanks in advanced.


Re: Which one is better? - ISmokezU - 19.07.2017

Yeah but you don't need it.

PHP код:
SaveBusiness(businessid

    new 
query[600]; 
    
mysql_format(MHandlequerysizeof(query)
        , 
"UPDATE businesses SET OwnerName = '%s', Name = '%s', Type = %d, Price = %d, Stock = %d, Balance = %d, ExteriorX = %f, ExteriorY = %f, \
          ExteriorZ = %f, ExteriorVW = %d, InteriorX = %f, InteriorY = %f, InteriorZ = %f, InteriorID = %d, InteriorVW = %d WHERE SQLID = %d"
        
Business[businessid][bOwnerName], Business[businessid][bName], Business[businessid][bType], Business[businessid][bPrice], Business[businessid][bStock], \
          
Business[businessid][bBalance], Business[businessid][bExteriorX], Business[businessid][bExteriorY], Business[businessid][bExteriorZ], Business[businessid][bExteriorVW], \
          
Business[businessid][bInteriorX], Business[businessid][bInteriorY], Business[businessid][bInteriorZ], Business[businessid][bInteriorID], Business[businessid][bInteriorVW], Business[businessid][bSQLID]
    ); 
    
mysql_query(MHandlequery); 
    return 
true




Re: Which one is better? - DuyDang2412 - 19.07.2017

Quote:
Originally Posted by ISmokezU
Посмотреть сообщение
Yeah but you don't need it.

PHP код:
SaveBusiness(businessid

    new 
query[600]; 
    
mysql_format(MHandlequerysizeof(query)
        , 
"UPDATE businesses SET OwnerName = '%s', Name = '%s', Type = %d, Price = %d, Stock = %d, Balance = %d, ExteriorX = %f, ExteriorY = %f, \
          ExteriorZ = %f, ExteriorVW = %d, InteriorX = %f, InteriorY = %f, InteriorZ = %f, InteriorID = %d, InteriorVW = %d WHERE SQLID = %d"
        
Business[businessid][bOwnerName], Business[businessid][bName], Business[businessid][bType], Business[businessid][bPrice], Business[businessid][bStock], \
          
Business[businessid][bBalance], Business[businessid][bExteriorX], Business[businessid][bExteriorY], Business[businessid][bExteriorZ], Business[businessid][bExteriorVW], \
          
Business[businessid][bInteriorX], Business[businessid][bInteriorY], Business[businessid][bInteriorZ], Business[businessid][bInteriorID], Business[businessid][bInteriorVW], Business[businessid][bSQLID]
    ); 
    
mysql_query(MHandlequery); 
    return 
true

So what if I have to use the enormous string size to format once and query it? Should I separate the format?


Re: Which one is better? - Hansrutger - 19.07.2017

Change mysql_query into mysql_tquery and magic will happen. Once you have that it won't matter that much which path you choose.


Re: Which one is better? - GoldenLion - 19.07.2017

You shouldn't do that at all. Update something only when it changes, for example when someone buys the business update the OwnerName column or when the name is changed update the Name column, etc.


Re: Which one is better? - Abagail - 19.07.2017

Unless you're saving business data excessively, you could just update data as it changes.


Re: Which one is better? - Gammix - 19.07.2017

Quote:
Originally Posted by DuyDang2412
Посмотреть сообщение
I don't know which one is better for a roleplay server. The number one will be slower than the second but the second will use too much memory because it has the variable 'query' with 2048 sizes.
Thanks in advanced.
Is that really an issue, about memory?
Memory is so cheap today so you don't need to worry about it. Just make a bigger string size.


Re: Which one is better? - DuyDang2412 - 19.07.2017

I wanna update all every 1 hour just in case, not so often.
REP+ all!
Quote:
Originally Posted by Gammix
Посмотреть сообщение
Is that really an issue, about memory?
Memory is so cheap today so you don't need to worry about it. Just make a bigger string size.
Got it, bro. I just wanna optimize my server as much as possible.


Re: Which one is better? - Paulice - 19.07.2017

Use the second one, add LIMIT 1 to your SQL statement and use mysql_tquery instead of mysql_query.


Re: Which one is better? - DuyDang2412 - 19.07.2017

Thank you guys! mysql_tquery is such a magic!