Everything About TypeScript Declarations

It turns out that Typescript declaration files seem to be one of the complex things to grasp because of the lack of the documentation and vague explanations from community. In this article, We will…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Running a SQLite Database in PHP with Docker

First, let’s take a look at a simple PHP script that connects to a SQLite database (called testing.sqlite), creates a table, and adds 3 users. Save this file as index.php:

In order to run the code above, we can use Docker’s PHP 7.2 image:

The user count shown is based on the number of users we created in the PHP script. If you add more users, you could see a higher number there.

While this simple example works, where did our data go?

Since we didn’t mount the SQLite data folder from the container onto our localhost, the data is gone when the container is gone. One simple fix for this is to change our PHP code to use a SQLite file stored in our /appdirectory. Just change the first line to:

And run the same Docker command as before:

Now you’ll see a file (called testings.sqlite) in the same directory with your index.php file. If you run the Docker run command again, you’ll get User count: 6 as it uses the same database file as it did the first time. In this way, you can ensure that your SQLite database uses the same data every time you run your container.

Add a comment

Related posts:

Business Professional

For the office and pretty much only the office. Fairly straight-laced, it’s sometimes hard to innovate within this dress code, but we swear it is possible.

Automating Azure Deployments with ARM Templates

Our lead DevOps engineer, and all round nice guy Mark Vallins, shares his experience with Azure deployments using ARM templates, Powershell and Visual Studio Code. A great video walkthrough for…

Most important lesson I learned from Amal fellowship!

Best journey of my life with Amal Academy as a fellow student is almost completed. These three months of immense recreational learning taught me millions of small but essential lessons of life. To…