I’m trying to make a site, where the owner has a CMS page where he can insert/edit his contact info and about info.
When I thought about it, I found that I’ll be creating a table called info with only one single row, containing tel, facebook, twitter and E-mail columns.
Is this a good idea to store a single row only in a database, or should I just store it in a system file or something ?
I really need suggestions on this.
I have a few suggestions for you.
First I would strongly suggest making an interface in your code that represents your “database”. The advantage of this is that you can change the storage on the back end whenever you like. You might start storing this data on the file system and then change to a database. Either way your code would point to something like IRepository.
You would have things like this then:
public class FileRepository : IRepository { }
public class MySQLRepository : IRepository { }
This will help you keep the code the same while giving you the flexibility to change how you persist the data.
Secondly I would name your table more descriptively. Is this user info? User settings? Taking the time to pick a descriptive name will help you in the future.
Thirdly … and this is maybe making this a bigger deal than it really is, but consider whether you’d like a relational database or a document database. With a document database, you can store the “user info” information in one document. This makes it very easy to serialize/de-serialize your objects in code without having to do joins, etc. An example:
There are advantages and disadvantages to both. If you want to use a relational database (SQL Server, MySQL, Oracle), then only make fields for things you believe won't change much over time. If you want to store settings/user preferences, there are better options than just adding a field.
Hope that makes sense.