I have some PHP code that just needs to store a single number so that it can be retrieved each time someone uses the site. I could either store this in a database or in a text file, however does anyone know which is faster to read/write? Connecting to a database and then reading/writing the value from a table column, or opening a text file and reading/writing it there? Thanks.
reading from a file is always fast provided you dont have much data. if you have large data, using a database is the best efficient one. dont forget that file read/write might consume cpu. If you learn database queries, on the long run it can become quite useful.
i tried myself like what you think, few years ago when i started as programmer. all i had was lot of problems with reading and writing file using php with the help of filehandling functions. It turned out to be a nightmare for me. i do database even for very small data. With mysql queries everything was just on the fly. If i want to port database to other server its just as easy unlike files where you have to worry about users and their permissions everytime.
olddocks is right. Using Database, is much easier and safe to implement than a file, even if simple. Files are easy to read, but when it comes to writing, it becomes a knightmare, a living hell if you have to update!
As long as your site doesn't get more than 5.000 visitors / day - go for the DB. Files are a pain in the ass.