Hướng dẫn php postgresql insert query

Last update on August 19 2022 21:51:31 [UTC/GMT +8 hours]

INSERT Command

This document discusses how to insert data into a table using PostgreSQL INSERT command. We have also covered how to do the same using PHP-PostgreSQL.KJVQCSV69JFX

Usage

Following is the usage of PostgreSQL INSERT command for inserting data into a single row of a PostgreSQL table.

INSERT INTO table_name [column1, column2, column3 .....] VALUES [value1, value2, value3....] 

Where table_name is the associated table, column1, 2, 3 are column names and value 1, 2, 3 are values to be inserted.

Insert single row

Structure of the table

Following is the structure of the table where we will insert data.

Command to insert data

View data

This is from where you can check data using PgAdmin III.

This is the data we have entered using INSERT command -

Insert multiple rows

Here is the command to insert multiple rows in a PostgreSQL database.

INSERT INTO book [book_id, name, price, date_of_publication] VALUES ['HTML01', 'HTML Unleashed', 19.00, '08-07-2010'], ['JS01', 'JavaScript Unleashed', 22.00, '01-05-2010'], ['PHP01', 'PHP Unleashed', 19.00, '01-04-2010'];

Insert data: PHP-PostgreSQL

The following example code is to insert data into the 'book' table using PHP. Assume that the name of the file saved with this code is insert.php.



Insert data to PostgreSQL with php - creating a simple web application


li {
list-style: none;
}



Enter data into book table

  • Book ID:
  • Book Name:
  • Price [USD]:
  • Date of publication:

Chủ Đề