I want to make a backup to my database, but before writing to a CSV file some data manipulation is needed.
My idea is first create an array or linked list format the data (mainly insertion and calculations for specific items, including insertion in the middle of the array, the order is important), and then just write the array items to file.
Each item has the same fields.
The ammount of data is really big.
What is prefferable in this case? Array or Linked List?
I want to make a backup to my database, but before writing to a
Share
Leaving aside the relative merits of whatever you’re trying to do with this database backup, two considerations for you are “how do I locate entities within my list/array” and “do I care about my memory footprint?”
Depending on how you plan to manipulate the data, it’s usually convenient to be able to use some form of index to locate a data entity, so that you don’t have to trawl an array or a linear linked list to find it.
Some form of hashing is probably required to quickly locate a specific data entity. You can implement this with linked lists, or you could just use arrayname[‘index’] which may be much simpler (depending on how you plan to navigate and manipulate all this data).
You also mentioned that the amount of data is really big. So not only does that underline the importance of indexing performance but it also suggest that loading the entire lot into memory, via array or linked list, might not be the best approach.
Personally, I’d use the database itself to help with this…clone to a temporary table, do your manipulations, insertions and calculations with that. You should be able to use the PHP database API for whatever database you’re using to do all this fairly easily.
Certainly a lot easier than reading a table into memory and diddling it directly, I reckon 🙂
You can then give the user the option to keep the “new” (temporary) table, or cancel and retain the original. Hope this helps.