Storing form results in a flat file is easy, but it doesn’t let you manipulate the results easily. If you want to look at your data later you almost always want to store the data in a SQL database. SQL allows you to run queries on your data to see only parts of the data: only the votes from today, or only the votes from one IP address.
For purposes of this tutorial, I’m going to use SQLite, because it is available by default in PHP.
- Create storage
- Create storage in PHP: Hot Pages: SQLite
- Manage your data
- Manage your data in PHP: Hot Pages: SQLite
- Other database servers
- We used PHP’s “PHP Data Objects” method of accessing the database, so everything should work the same in other databases that also use PDO. PHP’s PDO system is designed to make your database code portable. If you transfer your database from SQLite to another database server, you should be able to make it work by changing only one line, the line where you create the database object.