In this part of tutorial we will be dealing with the inserting values into MYSQL database with the help of php. php is the open source server side scripting language which is utilized for creating an api.

In the previous part of the tutorial we have dealt with the fetch of values from the database.Now let’s go through how is it created that is inserted.

As you may have already know the CRUD operations if not please refer my previous tutorial.

Inserting values into MYSQL using PHP


So let’s get started now

Step 1:


This is first step of connecting to the database here we provide the details required


  1.  Hostname is the place where the database is.
  2.  Username for the user access.
  3.  Password  is required for maintaining security for local host this will be empty.
  4.  DBName  this will select the database out of all your databases present on your server



Using all these parameters will help us connect

With the help of the connect file we can establish a connection to database and from there execute transactions by passing query’s like insert, delete, update etc.,

Step 2:


The first step is to connect to database using the above mentioned process by specifying the file at start


Then accept the inputs from the user via API i.e., the key parameter by which we can search the table to find the exact record we need to fetch.

Save the value and save it to variable as below


Now write a SQL query to select the values from table using the key parameter as the constraint.


Now call the connection and thereby execute the SQL query as


Create an array to store the result accordingly


fetch the data from tables according to the row wise as


echo the encoded array list


finally close the database



For full detailed video tutorial visit the link below


Show Buttons
Hide Buttons
Read previous post:
Inserting values into MYSQL using PHP