How to connect to and operate a PostgreSQL database using php, postgresql database _ PHP Tutorial

Source: Internet
Author: User
The method for connecting and operating the PostgreSQL database in php, postgresql database. Methods for connecting to and operating a PostgreSQL database using php. This document describes how to connect to and operate a postgresql database using php. Share it with you for your reference. The method for connecting to and operating the PostgreSQL database in php is as follows:

This article describes how to connect to and operate a PostgreSQL database using php. Share it with you for your reference.

The specific implementation method is as follows:

The code is as follows:


$ Pg = @ pg_connect ("host = localhost user = S password = sa dbname = employes ")
Or die ("can't connect to database .");
$ Query = "select * from employes order by serial_no ";
// $ Query = "insert into employes values (10008, 'Susan ', '2017-09-04', '80', '50 ')";
$ Result = @ pg_query ($ pg, $ query) or die ("can't run query to table .");
// Echo pg_num_rows ($ result); // number of records output to be queried
// If ($ result)
//{
// Echo "recrods inserted sucessfully! ";
// Echo pg_affected_rows ($ result); // Number of output records inserted
//}
// Instance 1 [pg_fetch_row]
Echo"


















";Echo" ";Echo" ";Echo" ";Echo" ";Echo" ";For ($ I = 0; $ I{$ Row = @ pg_fetch_row ($ result) or die ("can't fetch row from table .");$ Serial_no = $ row [0];$ Name = $ row [1];$ Birthday = $ row [2];Echo" ";Echo" ";Echo" ";Echo" ";Echo" ";}Echo"
Serial_noNameBirthday
$ Serial_no$ Name$ Birthday
";
// Instance 2 [pg_fetch_array]
// Echo"



















";// Echo" ";// Echo" ";// Echo" ";// Echo" ";// Echo" ";//// For ($ I = 0; $ I//{//// $ Row = @ pg_fetch_array ($ result) or die ("can't fetch row from table .");// $ Serial_no = $ row ['serial _ no'];// $ Name = $ row ['name'];// $ Birthday = $ row ['birthday'];// Echo" ";// Echo" ";// Echo" ";// Echo" ";// Echo" ";////}// Echo"
Serial_noNameBirthday
$ Serial_no$ Name$ Birthday
";
// Add, delete, and modify an instance
// $ Newrow = array ("serial_no" => "1006", "name" => "peter", "birthday" => ", "salary" => "90", "bonus" => "80 ");
// $ Reusult = @ pg_insert ($ pg, "employes", $ newrow) or die ("can't insert data to table .");
// If ($ reusult)
//{
// Echo "rechords inserted sucessfully! ";
//}
//
Pg_close ($ pg );

I hope this article will help you with PHP programming.

This article describes how to connect to and operate a PostgreSQL database using php. Share it with you for your reference. Details...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.