PHP Database Operation
Database Connection With PHP Database Object (PDO)
In this step, a connection is established using the necessary information to connect to the MySQL server. This information usually includes the server name, username, password and database name. Once the connection is established, database operations can be performed via the connection variable.
CRUD (Create, Read, Update, Delete) Operation:
Data Adding (Create):
In this step, data submitted by the user through a form is retrieved. This data is then used in the SQL query to add a new record to the database. After the added record is added to the database, a success or error message is notified to the user.
Data Reading (Read):
In this step, data is read from the database. The requested data is retrieved from the database using an SQL query and then this data is printed on the screen. This is usually done within an HTML table so that the data is displayed in an orderly manner.
Data Updating (Update):
This step retrieves the updated data submitted by the user via a form. This data is then used in a SQL query to update the data for a particular record. When the update process is successful, a success message is displayed to the user, otherwise an error message is displayed.
Data Deleting (Delete):
In this step, the ID of a record that the user wants to delete is obtained. An SQL query is created using this credential and the relevant record is deleted from the database. When the deletion is successful, a success message is displayed to the user, otherwise an error message is displayed.