computermax2328 Posted October 8, 2012 Share Posted October 8, 2012 Hello Everyone, I was wondering what the best practice would be for storing a blog article. I am currently building a blog and I was just wondering what technique everyone used. All I did was simple store it in a MYSQL Database as a long text. I was also thinking about storing it in a folder somewhere as well. What do you think?? Quote Link to comment Share on other sites More sharing options...
Beeeeney Posted October 8, 2012 Share Posted October 8, 2012 I would do exactly what you described; store it in a database as a long text. Though I'm new to PHP so the experts on here might have other ideas. You could then just call it by ID in your code. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 8, 2012 Share Posted October 8, 2012 I was also thinking about storing it in a folder somewhere as well. I see nothing to be gained from storing the same content in the DB as well as in a flat file. It would take more overhead and create greater opportunity for the content to get out of sync between the two. Besides, if you can't rely upon whatever storage method you are using then you are using the wrong method. As to what field type you use is dependent upon how much and what type of content you would be storing. Longtext would work (supporting up to 4,294,967,295 characters), but that might be overkill to me. I would think that a medium text (supporting up to 16,777,215) characters would more than suffice. That would be more than 4,000 pages of content on a normal double-spaced printed page! By comparison a "normal" text/blob field (65,535 characters) would provide room for up to 16 pages of content on a double-spaced printed page. There are performance/storage costs to using larger fields than needed. But, to be honest, I'm not sure of all the ramifications. So, I would use the smallest field type that is larger than anything you would ever expect to have to save. Quote Link to comment Share on other sites More sharing options...
computermax2328 Posted October 8, 2012 Author Share Posted October 8, 2012 The only reason I want to store it as a file on the database is to have a secondary backup. It can't hurt. I will probably stick with medium text. It seems like the best idea without overkill. Just looking for some input. Quote Link to comment Share on other sites More sharing options...
kicken Posted October 8, 2012 Share Posted October 8, 2012 The only reason I want to store it as a file on the database is to have a secondary backup. It can't hurt. You'd probably be better off using that disk space to store a .sql file backup of the whole database. If anything happens to the database you can restore it from one of the backup sql files and be on your way again rather than having to try and import a bunch of text or html files you wrote out. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 9, 2012 Share Posted October 9, 2012 I concur with kicken. The only reason I want to store it as a file on the database is to have a secondary backup. It can't hurt. Yes, it can hurt. You likely have a process to allow users to edit blogs. You may end up with multiple methods of editing a blog. You would then have to ensure each method is updating both the database and the flat file consistently. Plus, you would be using resources that would be better utilized elsewhere. Plus, editing/updating flat files is much more problematic than database records and could lead to errors. I think you wanting to do this comes from a lack of having much experience with databases. I know that in my early days of programming I preferred to store some data in a file rather than in a DB because I just "didn't get it". Quote Link to comment Share on other sites More sharing options...
computermax2328 Posted October 9, 2012 Author Share Posted October 9, 2012 Good call! That makes a lot of sense. Yeah these are my early days of PHP. You will find me on here a lot talking about proper practices. I try not to flood the forum everyday, but I do like to strike conversation every once in a while. Thanks for the insight! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.