Which one is better?
#1

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.
Reply
#2

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

Reply
#3

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?
Reply
#4

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

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.
Reply
#6

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

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.
Reply
#8

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.
Reply
#9

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

Thank you guys! mysql_tquery is such a magic!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)