Prisma PostgreSQL Setup
Configuration Steps
- Modify your
schema.prismafile to specify PostgreSQL as the database provider. - Edit the
.envfile with your PostgreSQL database connection details. - Create and apply migrations as necessary.
schema.prisma Configuration
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
By default Prisma PHP generate the schema.prisma file with PostgreSQL as the provider, And the configuration above is the default configuration for PostgreSQL.
.env Configuration
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=public"
Replace USER, PASSWORD, HOST, PORT, and DATABASE with your actual PostgreSQL database details to ensure a secure and correct connection.
Integrating PostgreSQL with Prisma PHP using XAMPP
To interact with PostgreSQL, you may need to enable the PostgreSQL extension in your XAMPP's PHP configuration.
Enable PostgreSQL Extension
- Locate your XAMPP installation directory and find the
php.inifile. This is typically found in thephpsubdirectory. - Open the
php.inifile in a text editor. - Search for the line that looks like
;extension=pgsqland;extension=pdo_pgsql. Remove the semicolon (;) at the beginning of each line to uncomment these lines. It should look like this:extension=pgsql extension=pdo_pgsql - Save the changes to
php.iniand restart your XAMPP server for the changes to take effect.
This step is necessary to enable your PHP applications running on XAMPP to interact with PostgreSQL databases using the native PHP extensions.
Conclusion
You have now successfully integrated PostgreSQL with Prisma PHP in a XAMPP environment. This setup allows you to develop full-stack applications using Prisma as your ORM with PostgreSQL as the database.
Next Step
Go to Prisma Command to migrate your database.