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"
Serial_no | ";Echo"
Name | ";Echo"
Birthday | ";Echo"
";
";Echo"
$ Serial_no | ";Echo"
$ Name | ";Echo"
$ Birthday | ";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 );
Method 2 postgresql data connection method and Operation instance. $ pg = @ pg_connect (host = localhost user = S password = sa dbname = employes )...