This guide explains how to persist jspreadsheet data using postgresql.
Download the project to your local machine. Ensure that Docker is installed and running.
Navigate to the project’s root folder and run the following command to start the necessary Docker containers:
docker-compose up
Open a new terminal, navigate to the project’s root folder, and access the PHP container by running:
docker-compose exec php bash
Inside the PHP container terminal, install the required PHP dependencies using Composer:
composer install
In a new terminal, navigate to the root folder and access the PostgreSQL container:
docker-compose exec postgresql bash
Once inside the PostgreSQL container, follow these steps to create a users
table:
-
Access PostgreSQL and create the
test
database:psql -U postgres
-
Create a new database:
CREATE DATABASE test;
-
Connect to the
test
database:\c test
-
Create the
users
table:CREATE TABLE users ( user_id SERIAL PRIMARY KEY, username VARCHAR(50), email VARCHAR(100) );
Verify that the table name in your public/index.php
matches the database table you created. In this example, the table is users
:
$jss = new \Jspreadsheetdb($database, 'users');
Open your browser and navigate to http://localhost:8009. Any updates made in the spreadsheet will now persist in the database table.
- You can further customize the database structure depending on your needs.
- Ensure that your Docker containers are running before attempting to access the site.