Two methods and operations for connecting data with PostgreSQL _ PHP Tutorial

Source: Internet
Author: User
Two PostgreSQL data connection methods and Operation instances. Two PostgreSQL data connection methods and Operation instances two postgresql data connection methods and Operation instances. $ pg @ pg_connect (hostlocalhostuser?spasswordsadbnameemployes) two PostgreSQL data connection methods and Operation instances

Two postgresql data connection methods and Operation instances.

$ 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"






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" ";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 );

Method 2 postgresql data connection method and Operation instance. $ pg = @ pg_connect (host = localhost user = S password = sa dbname = employes )...

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.