PHP connection and operation of PostgreSQL database method, PostgreSQL database _php Tutorial

Source: Internet
Author: User

PHP connection and operation of PostgreSQL database method, PostgreSQL database


This article describes the PHP connection and operation of the PostgreSQL database method. Share to everyone for your reference.

The implementation method is as follows:

Copy the Code code as follows:
$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
//}
Example one [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]; $birt Hday= $row [2]; Echo "; Echo "; Echo "; Echo "; Echo "; } Echo
Serial_noNameBirthday
$serial _no$name$birthday
";
Example two [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, modify instance
$newrow =array ("serial_no" = "1006", "name" and "Peter", "Birthday" and "1990-07-03", "salary" and "All", "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 is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/932488.html www.bkjia.com true http://www.bkjia.com/PHPjc/932488.html techarticle PHP Connection and operation of PostgreSQL database method, PostgreSQL database This article describes the PHP connection and operation of the PostgreSQL database method. Share to everyone for your reference. Concrete Reality ...

  • 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.