1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Best way to store this data?

Discussion in 'Development' started by HittmanA, Jan 9, 2017.

  1. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    I need to be able to store data formatted like this:
    Code:
    Factions:
    [
    Test1:[Leader: Test, Officers: [Me, You], Members: [Other, People]],
    etc.,
    etc.
    ]
    What is the best data storage format (YAML,ENUM, etc.) and how should I go about storing/retrieving it? Thanks in advance!
     
  2. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Store it in a Config.yml (YAML). Or if u have a database use it.
     
  3. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    Ok thanks
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    json also works!
     
    HittmanA likes this.
  5. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    Question. How could one root associative array to the YAML when it is first made?
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Ezpz,
    PHP:
    /** @var Config $config */
    $assoc = [
        
    "Test" => [
            [
                
    => "Hello there",
                
    => Item::get(Item::STONE016)
            ]
    ];

    //Saving.
    $config->set("assoc"$assoc);
    $config->save();

    //Retrieving
    $array $config->get("assoc");

    //It's the same way you save / return strings.
    //Most would go with serialization if the array is big (just to save time and memory, I could be wrong).

    //Saving
    $config->set("assoc"serialize($assoc));
    $config->save();

    //Retrieving
    $array $config->get("assoc");
    $array unserialize($array);
     
    HittmanA likes this.
  7. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    json is always better unless you wanna store bigger amount of data in the array.
     
  8. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    I have no idea how much data will be stored by a server owner. However, now that I think about it, I doubt it would be large enough to need YAML.
     
  9. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Each thing has it's own purpose and I don't think YAML's purpose is to store data, I think it's more like an easily managable configuration file. For storaging stuff it is a better idea to use databases, for example: SQLITE3, MySQL, MySQLi, and many others to mention. If there isn't really much to store, you can save that data in a JSON compressed file.
     
    jasonwynn10 likes this.
  10. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    Some people may not have access to a MySQL DB.
     
  11. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Well, not MySQL, but you can always use a SQLITE3 database. If you did not know, every pocketmine server comes with one of "those".
     
    Last edited: Jan 10, 2017
    jasonwynn10 and HittmanA like this.
  12. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    If you are storing strings, go with JSON.

    When I used YAML, the line breaks did not save up whereas in JSON format, it did.

    I mainly use .sl (Config::SERIALIZED) format as it maintains the original code.

    Do not store serialized (serialize()) data in JSON. It is useless.
    Use json_encode() and json_decode() instead of serialize() and unserialize() if you're going for JSON
     
    HittmanA likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.