This project is an example CLI application demonstrating how to use Neon PostgreSQL (a fully managed cloud PostgreSQL platform) in combination with Rune and RedBeanPHP. The application allows you to perform CRUD operations on a user
table directly from the CLI, making it perfect for developers who want a lightweight, fast, and flexible way to interact with a database without building a full web interface.
The project leverages:
- Neon PostgreSQL – cloud-hosted PostgreSQL database
- Rune – for CLI management and scripting
- RedBeanPHP – lightweight ORM for PHP
Features
- Create, read, update, and delete users using CLI commands.
- Easily create database tables via scripts.
- Works with Neon PostgreSQL in the cloud.
- Clean, simple, and easy-to-extend structure.
Installation & Setup
Follow these steps to get started:
- 1. Clone the repository
git clone https://github.com/AnwarAchilles/example-online-postgre.git
cd example-online-postgre
- 2. Load vendor packages
composer install
- 3. Configure database connection Edit the main setup file where RedBean connects to Neon PostgreSQL. Replace placeholders with your Neon credentials:
$NEON_HOST = '';
$NEON_DB = '';
$NEON_USER = '';
$NEON_PASS = '';
R::setup(
"pgsql:host=$NEON_HOST;dbname=$NEON_DB;sslmode=require",
$NEON_USER,
$NEON_PASS
);
Using placeholders keeps your credentials safe for sharing or pushing to a repository.
Running the Application
To start the CLI application:
php cast
This will show available commands and let you run scripts, manage users, or view results.
# R E G I S T E R E D.
♦ php cast script
#≈ runs a script, e.g., creating database t
ables.
♦ php cast result
#≈ lists all user emails in the database.
♦ php cast create
#≈ create a new user, --email=(string)
♦ php cast update
#≈ update an existing user, --id=(int) --em
ail=(string)
♦ php cast delete
#≈ delete an existing user, --id=(int)
Step by Step
- 1. Create the user table
php cast script
This runs the script to create a user table if it does not exist.
- 2. Add a new user
php cast create --email=demo@mail.com
Adds a new user to the database.
- 3. View all users
php cast result
Lists all emails currently stored.
- 4. Update a user’s email
php cast update --id=1 --email=updated@mail.com
Updates the email for the user with id=1.
- 5. Delete a user
php cast delete --id=1
Removes the user from the database.
References
- Rune GitHub - Mangement Tools
- Neon - Managed PostgreSQL
- RedBeanPHP - Lightweight ORM for PHP
- Repo - Github Repository
Summary
This project is an example showing how to integrate and use Neon PostgreSQL in PHP, with database management organized neatly using Rune. It demonstrates how to perform CRUD operations via CLI commands with RedBean, making it easy to understand the workflow and structure when working with a cloud PostgreSQL database.
Top comments (0)