API
Prisma PHP provides a simple and user-friendly way to interact with your database. With Prisma PHP, you can easily query your database, create, update, and delete records, and perform other database operations with just a few lines of code. Prisma PHP makes it easy to work with your database, allowing you to focus on building your application instead of writing complex SQL queries.
You can use any front-end framework or library to interact with your API. For example, you can use popular JavaScript frameworks like React, Angular, or Vue.js to build a dynamic and responsive front-end application that communicates with your Prisma PHP API. Additionally, you can leverage mobile app development frameworks like React Native or Flutter to create mobile applications that seamlessly integrate with your Prisma PHP API.
To create your endpoint, follow these steps:
✔ Would you like to create a backend-only project? … No / Yes
- SelectYes
to create a backend-only project and install Prisma PHP.- Prisma PHP uses
route.php
as the default file for routing. This means that if you have a file namedroute.php
in a directory, it will be used as the endpoint for that directory. - Prisma PHP backend-only configuration file comes with a default
src/app/route.php
file. this is the default endpoint for your project. - Create a folder with the desired name, such as
products
, inside thesrc/app
directory. This is where you will create your endpoint using Prisma PHP's file-based routing. - Inside the created folder, create a file named
route.php
. - In the
route.php
file, define the logic for your endpoint and retrieve data from the database. - For creating a new route go to Routing documentation.
- For more information about the
route.php
file, you can refer to the Route File documentation. - For more information about the Prisma PHP ORM and getting started with setting up your database connection, you can refer to the
Prisma PHP ORM/Database Setup
documentation.
Project Structure for better organization:
.your-project-name // Your project root directory
├── .server // Prisma PHP backend-only project directory
├── .client // Your front-end project directory (React, Angular, Vue.js, etc.)
│ ├── // navbar
│ ├── // content
│ ╰── // footer
╰──...
Example Usage
use Lib\Prisma\Classes\Prisma;
$prisma = Prisma::getInstance();
$products = $prisma->product->findMany();
echo json_encode($products);
Note: The $prisma
variable is an instance of the Prisma class, which is used to interact with the database. The $prisma
variable provides access to the Prisma PHP query builder, which allows you to query the database and perform other database operations. For more information about the Prisma PHP query builder, you can see the Query Builder documentation.
Example Usage Received Data from API
use Lib\Prisma\Classes\Prisma;
$prisma = Prisma::getInstance();
$productName = $params->productName;
$products = $prisma->product->findMany([
'where' => [
'name' => [
'contains' => $productName
]
]
]);
echo json_encode($products);
Note: The $params
variable is a global variable that contains the request parameters, such as those from GET, POST, PUT, DELETE, etc. methods. This variable makes it easy to retrieve data from the request and use it in your query. for more info of $params
variable, you can see the Params documentation.