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"
Serial_no | ";Echo"
Name | ";Echo"
Birthday | ";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"
$ Serial_no | ";Echo"
$ Name | ";Echo"
$ Birthday | ";Echo"
";}Echo"
";
// Instance 2 [pg_fetch_array]
// Echo"
";// Echo"
";// Echo"
Serial_no | ";// Echo"
Name | ";// Echo"
Birthday | ";// 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"
$ Serial_no | ";// Echo"
$ Name | ";// Echo"
$ Birthday | ";// Echo"
";////}// Echo"
";
// 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...