One way to store and retrieve data is by reading and writing files directly to the filesystem of the computer that either PHP or Node.js is running on.
An alternative to reading and writing files is to read and write rows and columns of data into a database. Database servers can be accessed remotely so PHP or Node.js code can access a database even if it is running on a different computer than the web server. Data in a database is also divided up into rows and columns, which can make it easier to organize and store some data, like usernames, and harder to organize and store other data, like image files.
Some web hosting services duplicate an application across multiple web servers for faster response and more reliability. But each web server still has its own filesystem, so writing a file will only write to one web server, not all web servers. But since a database is accessed remotely, multiple web servers will still access the same database. A database can be viewed as a sort of remote shared filesystem that provides special data organization features. This can be a significant advantage and a convenience, even a necessity.
Files and databases both have their uses. Reading and writing files in PHP and how to convert PHP file handling code to Node.js was covered in the previous chapter. This chapter will cover using MySQL databases in PHP and how to convert PHP code that uses MySQL databases into Node.js.
MySQL is arguably the most popular database. Nearly all ...