Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8912345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:10:33+00:00 2026-06-15T04:10:33+00:00

I require the ability to store, modify and retrieve YAML data content in a

  • 0

I require the ability to store, modify and retrieve YAML data content in a MySQL database.

My project (and question) aims:

  • Parse .yml files into a PHP multi-dimensional array
  • Store these into a MySQL database
  • Allow modification of individual values within the database primary aim
  • Retrieve the values from the database, parse, and place back into a .yml file

Step 1 – An Example YAML file

string 'name:
  singular: null
  plural: null
fields:
  price:
    label: Preis
  company_id:
     label: null
     placeholder: null'

The important things to note here are that there could be an unlimited number of nested keys, and also keys and values may have the same name / data.

Step 2 – Place this into a PHP array

I’m using a library called Spyc to parse the YAML. This works great! It gives me the following:

array
  'name' => 
    array
      'singular' => null
      'plural' => null
  'fields' => 
    array
      'price' => 
        array
          'label' => string 'Preis' (length=5)
      'company_id' => 
        array
          'label' => null
          'placeholder' => null

My aim next is to store each of these in a MySQL database. So…

Step 3 – CSV them

Here I have written my own function, which is basically a long list of foreach()s to separate these details into the following array:

array
   0 => string 'name||singular||' (length=16)
   1 => string 'name||plural||' (length=14)
   2 => string 'fields||price||label||Preis' (length=27)
   3 => string 'fields||company_id||label||' (length=27)
   4 => string 'fields||company_id||placeholder||' (length=33)

Step 4 – MySQL DB

Logically, I’m trying to store these strings in a database. I’m not sure of the schema. I’m guessing value will be the end($array[$key] in a value column, and the key column will contain the rest of the elements in the array.

This will effectively allow me to change values within the database before pulling them back out, parsing and returning to the .yml file.

Step 5 – I’m LOST!

So I’m not sure what to do now. Currently I’m trying to parse these strings with the following logic:

  • The last value end($array[$key] is the value, and all previous elements in the array are the parent keys
  • Once I’ve gotten that code working, effectively turning those strings back into an array would be the next priority

There’s got to be a better way to do this. My main aim is to be able to update the individual values in the database. My main problem is the fact that the array dimension count is not constant.

How I can be helped

Please offer me:

  • More appropriate methods of achieving my project aims (see top) if there are any
  • The best way to store this data in the database allowing easy modification of values (for example the nulls you see in Step 1)
  • Upon returning this data from the database, a PHP function to return these keys and values to the exact structure of the original array (Step 2) so that I can use Spyc to convert this back to YAML and output to the .yml file.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:10:34+00:00Added an answer on June 15, 2026 at 4:10 am

    If you want to create a key-value store that can be serialized as YAML, you should probably just create that:

    CREATE TABLE key_values(
      id INT PRIMARY KEY AUTO_INCREMENT,
      parent_id INT,
      type VARCHAR(255),
      key VARCHAR(255),
      value VARCHAR(255)
    )
    

    In this case, id is how you refer to the root record, parent_id is a mechanism for linking in child records, type is used to distinguish between an array map and an indexed array. key and value are used to store the respective values.

    With this you should be able to create the appropriate records.

    An example from your data might be to create the root node:

    INSERT INTO key_values VALUES (parent_id, type, key, value)
      VALUES (NULL, 'map', NULL NULL)
    

    Then add in the values for the name key presuming id was 1 for the previous INSERT:

    INSERT INTO key_values VALUES (parent_id, type, key, value)
      VALUES (1, 'map', 'name' NULL)
    

    The process repeats recursively for each value:

    INSERT INTO key_values VALUES (parent_id, type, key, value)
      VALUES (2, 'string', 'singular' NULL),
             (2, 'string', 'plural' NULL)
    

    In any case, you’ll need to write a wrapper class for all this or it’ll be too complicated to use.

    In practice I’m not sure going through all of this trouble is going to be much easier than simply storing the YAML as-is inside a LONGTEXT field and calling it a day. Manipulating and re-saving is usually not that expensive. Iterating over a multi-tiered tree structure is.

    You’ll have to be careful to avoid stomping writes in race conditions for the pure YAML approach, though, but that’s nothing that can’t be solved using a revision column that tracks which version you’re saving against. Construct your UPDATE so that it won’t match:

    UPDATE yamls SET value='...', revision=93 WHERE id=20 AND revision=92
    

    If some other process had updated it already you would see the query failed to run and could handle it accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some rhetorical question regarding storing session data in Symfony. We can store
The question is pretty self-explanatory, I require the ability to open and control a
What I want is the ability to store name,object pairs. Unlike objC c#'s Dictionary
I have a system which has certain page content stored in the database. Within
As part of a BlackBerry project I'm working on I need the ability to
I develop Joomla websites/components/modules and plugins and every so often I require the ability
I am currently working on a website that requires the ability to overwrite the
require('fortunes') fortune('106') Personally I have never regretted trying not to underestimate my own future
require installed gems are not visible. Test with hpricot which I installed several times:
require 'coderay' puts CodeRay.scan('puts Hello, world!', :ruby).page This code will print full HTML page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.