MySQL Loading / Saving help
#1

Hello i am making a dynamic system with MySQL. now i was wondering how do i load, save from a MySQL Database on Filterscriptinit and exit??

i uses select * from obj. do i have to just to do that? also, i want to CreateObject on the positions saved in DB.. how do i set it? also tell me how do i save all objects inside table obj when FilterScript exits?

Thanks for help
Reply
#2

Please help me my FS is just stuck at Saving part.. others all done.. please help me..
Reply
#3

PHP код:
enum oInfo
{
    
modelid,
    
Float:X,
    
Float:Y,
    
Float:Z,
    
Float:rX,
    
Float:rY,
    
Float:rZ
};
new 
object 2000 ][ oInfo ]; 
PHP код:
stock laodObjects(playerid)
{
    
mysql_format(dbquerysizeof(query), "SELECT * FROM `objects`");
    
mysql_pquery(dbquery"loadObjects""d"sizeof(object));

PHP код:
forward loadObjects();
public 
loadObjects()
{
    new 
count 0rowsfields;
    
cache_get_data(rowsfieldsdb);
    for(new 
irowsi++)
    {
        for(new 
osizeof(object); o++)
        {
            
object[o][modelid] = cache_get_field_content_int(i"modelid");
            
object[o][X] = cache_get_field_content_float(i"X");
            
object[o][Y] = cache_get_field_content_float(i"Y");
            
object[o][Z] = cache_get_field_content_float(i"Z");
            
object[o][rX] = cache_get_field_content_float(i"rX");
            
object[o][rY] = cache_get_field_content_float(i"rY");
            
object[o][rZ] = cache_get_field_content_float(i"rZ");
            
CreateDynamicObject(object[o][modelid], object[o][X], object[o][Y], object[o][Z], object[o][rX], object[o][rY], object[o][rZ]);
            
count++;
            break;
        }
    }
    
printf("Loaded objects from MySQL: %d"count);
    return 
1;

Reply
#4

Hey thanks for help mate.. Just to ask, is those "X" and "Y" and others are Names of Columns in my Table Right?
REPed you

EDIT: i am sorry but i didnt understand mysql_pquery thing.. also why did you had Stock function and Public callback both also in FilterScriptInit, i have to use that Stock Function to load objects of Public? (i Guess its public one but still clearing doubt. then where to use stock function?)
Reply
#5

The above code will overwrite all the data on index 0 of "object" array. It will only store the data of the last row. The second loop shouldn't be used at all, only a checking about if rows are more than the size of the array to prevent run time error 4 nor "break;" which stops the loop.

You can also re-set rows to the last valid index if rows are more:
PHP код:
rows clamp(rows0sizeof object 1);
for (new 
orowso++)
{
    
object[o][modelid] = cache_get_field_content_int(o"modelid");
    
object[o][X] = cache_get_field_content_float(o"X");
    
object[o][Y] = cache_get_field_content_float(o"Y");
    
object[o][Z] = cache_get_field_content_float(o"Z");
    
object[o][rX] = cache_get_field_content_float(o"rX");
    
object[o][rY] = cache_get_field_content_float(o"rY");
    
object[o][rZ] = cache_get_field_content_float(o"rZ");
    
CreateDynamicObject(object[o][modelid], object[o][X], object[o][Y], object[o][Z], object[o][rX], object[o][rY], object[o][rZ]);
}
printf("Loaded objects from MySQL: %d"rows); 
Reply
#6

Is it working?
Reply
#7

Alright thanks for helping me i will test it as soon as i reach my home.. i am on highway right now :P

Ok but i didnt understand diffrence of
PHP код:
 stock laodObjects(playerid

    
mysql_format(dbquerysizeof(query), "SELECT * FROM `objects`"); 
    
mysql_pquery(dbquery"loadObjects""d"sizeof(object)); 

and Public function. and also in place of db in above stock i have to use my DB right?

Thank you to help me. you deserve +rep too.
Reply
#8

PHP код:
 mysql_pquery(dbquery"loadObjects""d"sizeof(object)); 
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_pquery i am not into MySQL much but i guess loadobjects needs to be a public function not a stock? i may be wrong because i am learning MySQL..
Reply
#9

Quote:
Originally Posted by ManIsHere
Посмотреть сообщение
Alright thanks for helping me i will test it as soon as i reach my home.. i am on highway right now :P

Ok but i didnt understand diffrence of
PHP код:
 stock laodObjects(playerid

    
mysql_format(dbquerysizeof(query), "SELECT * FROM `objects`"); 
    
mysql_pquery(dbquery"loadObjects""d"sizeof(object)); 

and Public function. and also in place of db in above stock i have to use my DB right?

Thank you to help me. you deserve +rep too.
Whoops! My fault. Stock's and public's name cannot be same. That should be like that:
PHP код:
stock laodObjects(playerid//select what you need

    
mysql_format(dbquerysizeof(query), "SELECT * FROM `objects`"); 
    
mysql_pquery(dbquery"loadObjects2""d"sizeof(object)); 

PHP код:
forward loadObjects2(); 
public 
loadObjects2() //do what you need with selected stuff

    
//...

Quote:
Originally Posted by ManIsHere
Посмотреть сообщение
and also in place of db in above stock i have to use my DB right?
Yes, you are right.
PHP код:
db mysql_connect(M_HostM_UserM_DataM_Pass); 
Reply
#10

Thank you for your help. i also have same doubt as GeorgeMcReary
Код:
 How to set auto increment in Object ID? like while loading and saving?
How do i add Object IDs? also,
Код:
 rows = clamp(rows, 0, sizeof object - 1);
What is object in that line? DB, Table or just a variable? i didnt not understand that one!!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)