Hey guys. I'm writing myself an online toolbox (for my code snippets). I have a "Snippets" table. My question is this. Would you save the snippet source in a Text column or would you have the snippet saved to a text file and the Snippet entry would reference the file name?

e.g. Snippets or Snippets2

66d53b10f23ce24db08dffd799cf70e2

Member Avatar for diafol

Depends what you want to do with it. Having the text file is handy as you can download it, although you can create one on the fly. Not sure if it makes too much difference. However, if you have a search facility on the code itself, then you'd be better to place it into a text field. Files may be vulnerable to overwriting if you upload same names. If you're only displaying one snippet at a time on a page and you're not going to have millions of records, perhaps it won't make much difference to the load time. You can test the time to load for both methods with microtime(). Just a few thoughts. I'm sure other contributors with have preferences and good reasons for them.

Thanks Diafol. Just what I needed to know.

Member Avatar for diafol

OK, perhaps it would be an idea un unsolve this and maybe attract a few more viewpoints. I don't think I gave you much sound advice, a few ramblings and half thoughts really. The beauty of the db only solution is that everything is "self contained", having data strewn over a db and a file system can have its difficulties.

If you do go down the link-to-file system, ensure that you only store the filename as you may wish to change the name of the directory at some point. In which case, you'd have to update every record in the DB. Also, before accepting a new file upload, check for the existence of file with that name and give yourself a prompt to confirm an overwrite or to be able to rename it before it's stored. Can be a pain.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.