Two method and operation example of PostgreSQL connection data

Source: Internet
Author: User
Tags postgresql
The code is as follows Copy Code

$PG = @pg_connect ("Host=localhost user=postgres 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 ', ' 1985-09-04 ', ' 80 ', ' 50 ')";
$result = @pg_query ($PG, $query) or Die ("can" t run query to table.);
echo pg_num_rows ($result); Output how many records are queried
if ($result)
//{
echo "Recrods inserted sucessfully!";
echo pg_affected_rows ($result);//Output How many records are inserted
//}

instance one [Pg_fetch_row]
echo "<table border=1>";
echo "<tr>";
echo "<td>serial_no</td>";
echo "<td>name</td>";
echo "<td>birthday</td>";
echo "</tr>";

for ($i =0; $i <pg_num_rows ($result); $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 "<tr>";
echo "<td> $serial _no</td>";
echo "<td> $name </td>";
echo "<td> $birthday </td>";
echo "</tr>";

}
echo "</table>";

//Instance two [Pg_fetch_array]
//echo "<table border=1>";
//echo "<tr>";
//echo "<td>serial_" No</td> ";
//echo "<td>name</td>";
//echo "<td>birthday</td>";
//echo "</tr>";
//
//for ($i =0 $i <pg_num_rows ($result); $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 "<tr>";
//echo "<td> $serial _no</td>";
//echo "<td> $name </td>";
//echo "<td> $birthday </td>";
//echo "</tr>";
//
//}
//echo "</table>";

//Add, delete, modify instance
//$newrow =array ("Serial_no" => "1006", "name" => "Peter", "Birthday" => "1990-07-03", " Salary "=>", "bonus" => "80");
//$reusult = @pg_insert ($PG, "employes", $newrow) or Die ("can" insert data to table.);
//if ($reusult)
//{
//echo "rechords inserted sucessfully!";
//}
//
Pg_close ($PG);

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.